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 (

user2560165
  • 149
  • 1
  • 2
  • 15
  • What about `file_get_contents('php://input')`? Like `print_r(json_decode(file_get_contents('php://input'),true));` – Quasdunk Oct 20 '13 at 12:31
  • 1
    have a close look at : http://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 – Ravish Oct 20 '13 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: http://www.jeffryhouser.com/index.cfm/2013/10/1/Calling-a-ColdFusion-CFC-from-AngularJS and also read this post which is PHP Specific: http://victorblog.com/2012/12/20/make-angularjs-http-service-behave-like-jquery-ajax/ – JeffryHouser Oct 20 '13 at 13:11
  • Open the browser's debugger & see what gets sent to the server. In Chrome, look in the Network tab – Foo L Oct 20 '13 at 13:14

1 Answers1

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

orange
  • 7,755
  • 14
  • 75
  • 139