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
Post a Comment