我使用
jQuery File Upload plugin by Blueimp将图像上传到服务器.问题是,发送服务器是admin.example.com,存储图像的接收服务器位于www.example.com上.相同的域,不同的子域.
XMLHttpRequest cannot load http://www.example.com/upload/. Origin http://admin.example.com is not allowed by Access-Control-Allow-Origin.
上传文件夹具有读取和写入权限.
我将在下面发布我的代码 – 如果有人能告诉我如何解决这个问题,请让我知道.以前我曾经问过这个问题,并尝试一些其他解决方案(iframe uploads和ftp文件移动).这些都不会对我的情况最好,如果我可以这样做,这将是最简单的
接收服务器
index.php
header('Access-Control-Allow-Origin: http://admin.example.com'); //I have also tried the * wildcard and get the same response
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type, Content-Range, Content-Disposition, Content-Description');
?>
error_reporting(E_ALL | E_STRICT);
require('UploadHandler.php');
$upload_handler = new UploadHandler();
发送服务器
main.js
$(function () {
'use strict';
// Initialize the jQuery File Upload widget:
$('#fileupload').fileupload({
// Uncomment the following to send cross-domain cookies:
xhrFields: {withCredentials: true},
url: 'http://admin.example.com/upload/',
disableImageResize: false,
dropZone: $('#dropzone'),
imageMaxWidth: 1800,
imageMaxHeight: 1800,
});
});
再次,我尝试了iframe文件上传,所以请不要建议,除非你可以给我完整的工作代码…
我也尝试过头(‘Access-Control-Allow-Origin:*’);但是得到相同的错误…我想在周末结束,所以我很感激任何帮助我可以得到. 🙂
谢谢!
编辑:以下是失败的OPTIONS请求的响应头
Allow:OPTIONS, TRACE, GET, HEAD, POST
Content-Length:0
Date:Tue, 27 Aug 2013 15:08:29 GMT
Public:OPTIONS, TRACE, GET, HEAD, POST
Server:Microsoft-IIS/7.5
X-Powered-By:ASP.NET