我寫了一個web服務,返回Json格式的數據,我試過並測試過,所有這些工作都很好。我現在正忙於編寫一個可以使用html(當然)和jquery來處理實際調用的Web服務的Web客戶端。Jquery ajax調用本地主機上的webservice錯誤
這是jQuery的的片段,我用做電話:
$(document).ready(function() {
$.ajax({
url: "http://localhost:8080/UserStore/webapi/myresource/4"
}).then(function(data) {
alert('id: ' + data.id + ", username: " + data.username + ", password: " + data.password + ", email: " + data.email);
});
});
在運行此我得到以下錯誤:
XMLHttpRequest cannot load
http://localhost:8080/UserStore/webapi/myresource/4
. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost
' is therefore not allowed access.
這......是所有法國人我......我不懂法語......所以你去了。
你在做一個跨域Ajax請求?如果是的話,在那裏設置適當的標題來訪問。 – Jai
允許跨域請求服務器端 –
@Relborg然後嘗試刪除'http:// localhost:8080'並添加'dataType:'json''。 – Jai