为了账号安全,请及时绑定邮箱和手机立即绑定

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 关注
  • 525 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信