問題描述
我正在嘗試在 js 中發布表單數據:
我有這個代碼:
var formData = new FormData();formData.append("用戶名", "Groucho");formData.append("accountnum", 123456);formData.append("afile", "2");var xhr = new XMLHttpRequest();xhr.open("POST", "http://xxxxx/xx.ashx",true);xhr.send(formData);
根據 )
現在跨瀏覽器 AJAX 文件上傳非常困難.您可以嘗試在 Javascript 中構建自己的表單標題/邊界(請參閱此處的答案:XMLHttpRequest POST multipart/form-data) 但是,我個人認為這不值得.
Im trying to post a form data in js :
I have this code :
var formData = new FormData();
formData.append("username", "Groucho");
formData.append("accountnum", 123456);
formData.append("afile", "2");
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://xxxxx/xx.ashx",true);
xhr.send(formData);
Formdata according MDN is not available in IE ( or unknown).
When I try this in FF :
( i think its fine...).
when I try in IE :
What is the solution to post form data ( or my data but in objective way) CROSSBROWSER ?
You didn't say which version of IE you're using. The formData object is not supported in IE9 or lower. XMLHTTPRequest2 (which contains the formData object) should be supported in IE10 (http://caniuse.com/xhr2)
Cross-browser AJAX file upload is very hard to do right now. You could try building your own form header/boundaries in Javascript (see answer here: XMLHttpRequest POST multipart/form-data) but, personally, I don't believe it is worth the effort.
這篇關于通過 JS 中的 XMLHttpRequest 對象發布表單數據?(跨瀏覽器)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!