ajax - How can I post data as form data instead of a request payload? -


In the code below, AngularJS calls the $ http method URL, and the XSRF object Submits as "request payload" (as described in the Chrome Debugger Network tab) JQuery $. The Ajax method calls the same call, but submits XSR as "form data".

How can I submit AngularJS to XSR as form data instead of a request payload? var url = 'http://somewhere.com/'; Var xsrf = {fkey: 'xsrf key'}; $ Http ({method: 'POST', url: url, data: xsrf}) Success (work () {}); $ .ajax ({type: 'post', url: url, data: xsrf, data type: 'jason', success: function () {}});

The following line must be added to the $ http object that has been passed:

  header: {'content-type': 'application / x-www-form-urlencoded'}   

and passed data should be changed URL-encoded string:

  & gt; $ .arm ({fkey: "key"}) 'fkey = key'   

So you have something like this:

  $ http ({method : 'Post', url: url, data: $ .human ({fkey: "key"}), header: {'content-type': 'application / x-www-form-urlencoded'}})   

to:

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -