Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
546 views
in Technique[技术] by (71.8m points)

php - How to post a data in Angular?

I try to make a post query to save my array in database. server side is PHP. My angular part:

$http({
            method: 'POST',
            url: "addOrder.php",
            data: myJsonedArray,
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        });

Angular make a post query to addData.php, but in php file my command

print_r($_POST); or print_r($_REQUEST); 

give me empty Array();

How to fix it? Thanks

UPDATE: if I try this example in jquery - I have he same result - empty array, but if I try with "test_var" - example works well:

$.post("addOrder.php", { "test_var": da }, function (data) {
            console.log(data);
        });

How to make the same result? I've tried

 $http({

            method: 'POST',
            url: "addOrder.php",
            data: { "test_var": da },
            headers: {'Content-Type': 'application/x-www-form-urlencoded'}
        });

but no result (

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Perhaps this helps: http://www.cleverweb.nl/javascript/a-simple-search-with-angularjs-and-php/

$data = file_get_contents("php://input");
$objData = json_decode($data);

Also, I find $resource much easier to use...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...