Xmlhttprequest & Formdata Not Submitting Data
I am trying to submit a form via ajax using the post method and a FormData object. Here is a simplified version of the JavaScript: var form=…; // form element var url=…; //
Solution 1:
The content type when sending a FormData object is multipart/form-data not url encoded. Further more the proper boundary must be set for the request, which the user is unable to do. For this XMLHttpRequest sets the correct content type with the required boundary. So all you have to do is not set the content type and it'll work.
var xhr=newXMLHttpRequest();
xhr.open('post',url,true);
//xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded");<--don't do thisvar formData=newFormData(form);
formData.append('update', true); // makes no difference
xhr.send(formData);
xhr.onload=function() {
alert(this.response);
};
Solution 2:
Change the name of the button to something other than "update" (and change it in your form['update'].onclick...
as well). I think its clashing with the value you are trying to set on the FormData to trigger the PHP code.
Post a Comment for "Xmlhttprequest & Formdata Not Submitting Data"