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 对象发布表单数据?(跨浏览器)


基础教程推荐
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01