{"id":3407,"date":"2014-03-24T03:57:29","date_gmt":"2014-03-24T03:57:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/24\/making-an-http-post-call-with-multipart-form-data-using-jquery-collection-of-common-programming-errors-2\/"},"modified":"2014-03-24T03:57:29","modified_gmt":"2014-03-24T03:57:29","slug":"making-an-http-post-call-with-multipart-form-data-using-jquery-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/24\/making-an-http-post-call-with-multipart-form-data-using-jquery-collection-of-common-programming-errors-2\/","title":{"rendered":"Making an HTTP POST call with multipart\/form-data using jQuery?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m trying to make a HTTP POST call with multipart\/form-data , using jQuery:<\/p>\n<pre><code>$.ajax({\n  url: 'http:\/\/localhost:8080\/dcs\/rest',\n  type: 'POST',\n  contentType:'multipart\/form-data',\n  data: 'dcs.source=boss-web&amp;query=data&amp;dcs.algorithm=lingo&amp;dcs.output.format=JSON&amp;dcs.clusters.only=true', \n  \/\/dataType: \"jsonP\",\n  success: function(jsonData) {alert('POST alert'); data=jsonData ; },\n  error : function(XMLHttpRequest, textStatus, errorThrown) {\n            console.log('An Ajax error was thrown.');\n            console.log(XMLHttpRequest);\n            console.log(textStatus);\n            console.log(errorThrown);\n          }\n});\n<\/code><\/pre>\n<p>It doesn&#8217;t work. Firebug returns an undefined error and the returned <code>XMLHttpRequst<\/code> object multipart field is set to false.<\/p>\n<p>What can i do to make this work with jQuery? And if it&#8217;s not possible is there a simple to achieve this?<\/p>\n<p>i.e. idon&#8217;t need to transfer files , just some data. but the server requires multipart.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m trying to make a HTTP POST call with multipart\/form-data , using jQuery: $.ajax({ url: &#8216;http:\/\/localhost:8080\/dcs\/rest&#8217;, type: &#8216;POST&#8217;, contentType:&#8217;multipart\/form-data&#8217;, data: &#8216;dcs.source=boss-web&amp;query=data&amp;dcs.algorithm=lingo&amp;dcs.output.format=JSON&amp;dcs.clusters.only=true&#8217;, \/\/dataType: &#8220;jsonP&#8221;, success: function(jsonData) {alert(&#8216;POST alert&#8217;); data=jsonData ; }, error : function(XMLHttpRequest, textStatus, errorThrown) { console.log(&#8216;An Ajax error was thrown.&#8217;); console.log(XMLHttpRequest); console.log(textStatus); console.log(errorThrown); } }); It doesn&#8217;t work. Firebug returns an undefined error and [&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-3407","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3407","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=3407"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3407\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}