我試圖在JSON
中向JSON
發出POST
請求,但我無法訪問服務器的文件以修改它們。將JSON POST請求發送到外部域而無需訪問服務器
當我做到這一點要求,我得到以下錯誤
的XMLHttpRequest無法加載https://external.com。否 「訪問控制 - 允許來源」標題出現在請求的 資源中。原因'https://www.ownedwebsite.com'因此不允許 允許訪問。
問題在哪裏?
下面是我使用的代碼:
$(document).ready(function(){
$("#submit").on('click', function(){
event.preventDefault();
$.ajax({
url: 'https://external.com',
type : "POST",
crossDomain: true,
dataType : 'json',
beforeSend: function (request)
{
//request.setRequestHeader("name", "value");
},
data : $("#formCart").serialize(),
success : function(result) {
alert('POST done.');
},
error: function(xhr, resp, text) {
alert('POST failed.');
}
})
});
});
我能做什麼呢?我需要做的就是以JSON格式發送這個POST表單數據。
[jQuery的阿賈克斯()POST請求的可能重複做它拋出405(不允許的方法)上RESTful WCF](http://stackoverflow.com/questions/17333013/jquery-ajax-post-request-throws-405-method-not-allowed-on-restful-wcf) – Sven
調用external.net的提供者並詢問他們將您添加到他們的CORS標頭 – madalinivascu
我需要執行請求而不能修改CORS h eader等..所以不,我不能「打電話給提供者」@madalinivascu –