亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

XMLHttpRequest無法使用jQuery加載URL

XMLHttpRequest無法使用jQuery加載URL

慕哥6287543 2019-08-17 15:25:03
XMLHttpRequest無法使用jQuery加我正試圖從“遠程”網站獲取一些json數據。我在99000端口上運行我的Web服務然后,我在99001端口上啟動我的網站(http:// localhost:99001 / index.html)。我收到以下消息:    XMLHttpRequest cannot load http://localhost:99000/Services.svc/ReturnPersons. Origin http://localhost:99001 is not allowed by Access-Control-Allow-Origin.即使我將我的網頁作為HTML文件啟動,我也會這樣:    XMLHttpRequest cannot load http://localhost:99000/Services.svc/ReturnPersons.Origin null is not allowed by Access-Control-Allow-Origin.Web服務返回數據。我嘗試捕獲這樣的數據項:var url = "http://localhost:99000/Services.svc/ReturnPersons";$.getJSON(url, function (data) {success: readData(data)});function readData(data) {    alert(data[0].FirstName);}而我正試圖得到這種結構:[{"FirstName":"Foo","LastName":"Bar"},{"Hello":"Foo","LastName":"World"}]你知道我為什么會收到這個錯誤嗎?
查看完整描述

3 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

在新的jQuery 1.5中,您可以使用:

$.ajax({
    type: "GET",
    url: "http://localhost:99000/Services.svc/ReturnPersons",
    dataType: "jsonp",
    success: readData(data),
    error: function (xhr, ajaxOptions, thrownError) {
      alert(xhr.status);
      alert(thrownError);
    }})


查看完整回答
反對 回復 2019-08-17
  • 3 回答
  • 0 關注
  • 590 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號