JS代码:
var url = "http://www.xxxx.com/xxxx/api/public/a.ashx";
var form = new FormData();
for (var i = 0; i < filecount; i++) {
var fileObj = document.getElementById('upload').files[i];
form.append('myfile', fileObj);
form.append('filename', fileObj.name);
}
form.append("folder", "../../../uploadfiles/factory/");
form.append("userId", userid); let xhr = new XMLHttpRequest();
xhr.open("post", url, true);
// xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.withCredentials = false;
xhr.onload = uploadComplete; //请求完成
xhr.onerror = uploadFailed; //请求失败
xhr.upload.onprogress = progressFunction;//进度
xhr.send(form);报如下错误:Failed to load http://www.xxxx.com/xxx/api/public/xxxx.ashx: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.xxx.com' is therefore not allowed access.但是我把 xhr.upload.onprogress = progressFunction;//进度 这句进度条代码删掉就不会报错了,不知道是什么原因。
看哪位遇到过,谢谢。
var url = "http://www.xxxx.com/xxxx/api/public/a.ashx";
var form = new FormData();
for (var i = 0; i < filecount; i++) {
var fileObj = document.getElementById('upload').files[i];
form.append('myfile', fileObj);
form.append('filename', fileObj.name);
}
form.append("folder", "../../../uploadfiles/factory/");
form.append("userId", userid); let xhr = new XMLHttpRequest();
xhr.open("post", url, true);
// xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.withCredentials = false;
xhr.onload = uploadComplete; //请求完成
xhr.onerror = uploadFailed; //请求失败
xhr.upload.onprogress = progressFunction;//进度
xhr.send(form);报如下错误:Failed to load http://www.xxxx.com/xxx/api/public/xxxx.ashx: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.xxx.com' is therefore not allowed access.但是我把 xhr.upload.onprogress = progressFunction;//进度 这句进度条代码删掉就不会报错了,不知道是什么原因。
看哪位遇到过,谢谢。
解决方案 »
- 请问jquery不跳转页面 给本页面传值怎么做呢?大神们
- JS构造树问题
- 请问img标签由position:static变成position:absolute的时候怎么设它的left和top属性呢?
- js动态加载src后,如何获取该加载页面执行的值
- js变量定义?
- 腾讯和新浪微博中是如何做到记住最后一次输入内容的(textarea)
- 请推荐一下有什么学习javascript的好书?
- 请问高手,为什么我把网页编码改成UTF-8,原来得JS函数全都失效了
- 请问关于用JAVASCRIPT时图片跳动的问题,急!!
- 50分:无询问关闭父窗口!
- JS如何实现后台打开网页并关闭该网页
- 函数申明提升的问题,求大神解答!!!
具体设置可百度一下跨域上传