Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 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 Answer

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...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...