Reputation: 14139
I have a php page, submit.php
, that takes the "data" parameter, get
or post
, and shoves it into a local file; I know it works because I tested it with jQuery using $.ajax
. However, I need to use AngularJS for this app. When I try this:
$http.post("submit.php", {"data": "foobar"});
nothing happens; the output file is unchanged. What am I doing wrong? How am I supposed to send the post request? It shows up in my chrome console as a post request, with the data I gave it, and yet has no effect on the file. Meanwhile,
$.post('submit.php', {'data': 'barfoo'});
works perfectly.
Upvotes: 1
Views: 67
Reputation: 944320
Open your developer tools. Open the Net tab. Run your Angular code. Run the jQuery code. Look at the request in the developer tools. Compare them.
Then see the manuals:
From the Angular manual:
If the data property of the request configuration object contains an object, serialize it into JSON format.
From the jQuery manual:
By default, data passed in to the data option as an object (technically, anything other than a string) will be processed and transformed into a query string, fitting to the default content-type "application/x-www-form-urlencoded".
PHP doesn't parse JSON formatted request bodies automatically.
Either:
Upvotes: 2