{"id":2948,"date":"2014-03-11T17:42:28","date_gmt":"2014-03-11T17:42:28","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/11\/angularjs-any-way-for-http-post-to-send-request-parameters-instead-of-json-collection-of-common-programming-errors-2\/"},"modified":"2014-03-11T17:42:28","modified_gmt":"2014-03-11T17:42:28","slug":"angularjs-any-way-for-http-post-to-send-request-parameters-instead-of-json-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/11\/angularjs-any-way-for-http-post-to-send-request-parameters-instead-of-json-collection-of-common-programming-errors-2\/","title":{"rendered":"AngularJS &#8211; Any way for $http.post to send request parameters instead of JSON?-Collection of common programming errors"},"content":{"rendered":"<p>I have some old code that is making an AJAX POST request through jQuery&#8217;s post method and looks something like this:<\/p>\n<pre><code>$.post(\"\/foo\/bar\", requestData,\n    function(responseData)\n    {\n        \/\/do stuff with response\n    }\n<\/code><\/pre>\n<p><code>requestData<\/code> is just a javascript object with some basic string properties.<\/p>\n<p>I&#8217;m in the process of moving our stuff over to use Angular, and I want to replace this call with $http.post. I came up with the following:<\/p>\n<pre><code>$http.post(\"\/foo\/bar\", requestData).success(\n    function(responseData) {\n        \/\/do stuff with response\n    }\n});\n<\/code><\/pre>\n<p>When I did this, I got a 500 error response from the server. Using Firebug, I found that this sent the request body like this:<\/p>\n<pre><code>{\"param1\":\"value1\",\"param2\":\"value2\",\"param3\":\"value3\"}\n<\/code><\/pre>\n<p>The successful jQuery <code>$.post<\/code> sends the body like this:<\/p>\n<pre><code>param1=value1&amp;param2=value2&amp;param3=value3\n<\/code><\/pre>\n<p>The endpoint I am hitting is expecting request parameters and not JSON. So, my question is is there anyway to tell <code>$http.post<\/code> to send up the javascript object as request parameters instead of JSON? Yes, I know I could construct the string myself from the object, but I want to know if Angular provides anything for this out of the box.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have some old code that is making an AJAX POST request through jQuery&#8217;s post method and looks something like this: $.post(&#8220;\/foo\/bar&#8221;, requestData, function(responseData) { \/\/do stuff with response } requestData is just a javascript object with some basic string properties. I&#8217;m in the process of moving our stuff over to use Angular, and I [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2948","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2948"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2948\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}