我正在尝试使用发布请求将文件发送到我的服务器,但是当它发送它时会导致错误:
$http.post($rootScope.URL, {params: arguments}, {headers: {
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Methods" : "GET,POST,PUT,DELETE,OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
}
Run Code Online (Sandbox Code Playgroud)
所以我用Google搜索了错误并添加了标题:
$http.post($rootScope.URL, {params: arguments}, {headers: {
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Methods" : "GET,POST,PUT,DELETE,OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
}
Run Code Online (Sandbox Code Playgroud)
然后我得到错误:
$http.post($rootScope.URL, {params: arguments}, {headers: {
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Methods" : "GET,POST,PUT,DELETE,OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With"
}
Run Code Online (Sandbox Code Playgroud)
所以我用谷歌搜索了那个,我能找到的唯一类似的问题提供了一个半答案然后关闭作为主题.我应该添加/删除哪些标题?
所以我试图在我的网站上获取文件上传的进度条.如果我只是上传资源
$.ajax({
url: $rootScope.URL, //Server script to process data
type: 'POST',
beforeSend: beforeSendHandler,
success: completeHandler,
error: errorHandler,
data: formData,
cache: false,
contentType: false,
processData: false
});
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但是如果我添加事件来听取进度:
$.ajax({
url: $rootScope.URL, //Server script to process data
type: 'POST',
xhr: function() { // Custom XMLHttpRequest
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ // Check if upload property exists
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // For handling the progress of the upload
}
return myXhr;
},
beforeSend: beforeSendHandler,
success: completeHandler,
error: errorHandler,
data: formData,
cache: false,
contentType: false, …Run Code Online (Sandbox Code Playgroud)