xmlhttprequest - Javascript: get all form keys and values and combine them as javascript object to use with XHR 2 FormData -


i use little snippet form values:

myform = document.forms[1]; email = myform.elements['email'];  

however, if plan use xhr 2's formdata, have this:

function sendform() {   var formdata = new formdata();   formdata.append('email', email);    var xhr = new xmlhttprequest();   xhr.open('post', '/server', true);   xhr.onload = function(e) { ... };    xhr.send(formdata); } 

is there way form data 1 javascript object can use formdata with?

just set form object formdata parameter:

function sendform() {   var myform = document.forms[1];   var formdata = new formdata(myform);    var xhr = new xmlhttprequest();   xhr.open('post', '/server', true);   xhr.onload = function(e) { ... };   xhr.send(formdata); } 

note: works input type="file"


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -