我的Ajax请求是这样的:jQuery的AJAX的网址无效
$.ajax({
url: self.opts.url.replace('//www.', '//'),
type: 'POST',
...
});
我把那.replace
只是要确定。因为我在opts.url
中的网址是"http://website.com/admin/upload-image/123"
。但我无法上传图像,因为我在控制台中出现错误:XMLHttpRequest cannot load http://www.website.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://website.com' is therefore not allowed access.
我在调试模式下仔细检查了URL,它总是没有www.
,但jQuery似乎总是添加它。这对我来说根本没有意义。
也是我从jQuery的error
功能得到:
jqXHR: Object (filled statusText with "error")
textStatus: "error"
errorThrown: ""
检查浏览器开发工具网络实际要求。最有可能被在终点重定向,而不是CORS启用 – charlietfl