0

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 (

4
  • What about file_get_contents('php://input')? Like print_r(json_decode(file_get_contents('php://input'),true)); Commented Oct 20, 2013 at 12:31
  • 1
    have a close look at : docs.angularjs.org/api/ng.$http#methods_post, try to debug from Angular side if it was success or fail. Inspect using firebug, see if your data is actually sent or not when a request happens Commented Oct 20, 2013 at 12:36
  • I Was going to point out setting the header; but it likes you're already doing that. Have you used a 'network sniffer' to examine the request? I write up a lengthy blog post about this on in relation to ColdFusion: jeffryhouser.com/index.cfm/2013/10/1/… and also read this post which is PHP Specific: victorblog.com/2012/12/20/… Commented Oct 20, 2013 at 13:11
  • Open the browser's debugger & see what gets sent to the server. In Chrome, look in the Network tab Commented Oct 20, 2013 at 13:14

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.