我的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