Post formdata via XMLHttpRequest object in JS ? ( cross browser)(通过 JS 中的 XMLHttpRequest 对象发布表单数据?(跨浏览器))
问题描述
我正在尝试在 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 对象发布表单数据?(跨浏览器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:通过 JS 中的 XMLHttpRequest 对象发布表单数据?(跨浏览器)


- 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
- addEventListener 在 IE 11 中不起作用 2022-01-01
- CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
- 失败的 Canvas 360 jquery 插件 2022-01-01
- 400或500级别的HTTP响应 2022-01-01
- 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
- Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
- Fetch API 如何获取响应体? 2022-01-01
- Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
- Flexslider 箭头未正确显示 2022-01-01