我的代碼是這樣使用REST API
$.ajax({
cache: false,
url: <Web Service URL>,
data: "{}",
type: 'GET',
crossDomain: true,
dataType: 'json',
success: function() { alert("Success"); },
error: function() { alert('Failed!'); },
});
我試圖使用jQuery訪問來自客戶端的REST API,但它給錯誤,如 XMLHttpRequest cannot load <Web Service URL>. Origin null is not allowed by Access-Control-Allow-Origin.
所以有人可以幫我解決這個錯誤..?
試試'JSONP'。 –
嗨Pushpesh,我也嘗試過JSONP,但它給出了相同的錯誤 –
你可以給我的網址,以便我可以試試看。您上面給出的網址無效,所以我無法驗證。 –