1

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.

Bluefire
  • 13,519
  • 24
  • 74
  • 118

1 Answers1

2

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:

Community
  • 1
  • 1
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335