【问题标题】:jQuery ajax working on local file but not working from a remote url?jQuery ajax 在本地文件上工作但不能从远程 url 工作?
【发布时间】:2011-09-27 17:34:45
【问题描述】:

我目前正在尝试使用 jQuery ajax 调用从远程 url 获取数据。

我只是使用一个基本的 jquery 函数来执行此操作。使用本地文件时,功能可以正常工作,但无法获取远程文件。

我在本地电脑上使用 Mamp 使用本地文件。

$.ajax({
url: "URL",
success: function(data) {
    $('#notification').html(data);
}
});

任何想法为什么这可能不起作用会很有帮助吗?

谢谢, 凯恩

【问题讨论】:

    标签: jquery ajax cross-domain


    【解决方案1】:

    听起来像Same origin policy。您可能需要使用JSONP

    【讨论】:

      【解决方案2】:

      当您说“远程文件”时,您的意思是来自另一个域吗?因为浏览器通常不允许这样做。

      看到这个JQuery external Ajax call not working in IE

      【讨论】:

        【解决方案3】:

        通常不允许跨域 ajax 请求。你可以看看这些答案:

        jQuery AJAX cross domain

        problem with cross-domain ajax calls

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-11-20
          • 1970-01-01
          • 2023-04-03
          • 2016-09-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多