代码之家  ›  专栏  ›  技术社区  ›  Tom Gullen

(简单)jquery ajax不返回数据

  •  1
  • Tom Gullen  · 技术社区  · 14 年前

    警告框将不显示任何内容,并且在显示Google页面时不会返回任何URL中的任何数据!有什么想法吗?我之所以使用post,是因为我试图让它也发送querystring数据。

        $.ajax({
            type: "POST",
            url: "http://www.google.com",
            success: function(msg) {
                alert("Data Saved: " + msg);
            }
        });
    
    3 回复  |  直到 14 年前
        1
  •  3
  •   Muneer    14 年前

    汤姆,

    您正在执行跨域脚本。

    将URL更改为您自己域中的文件。

    $.ajax({
            type: "POST",
            url: "anyfileinYourDomain.xxx",
            success: function(msg) {
                alert("Data Saved: " + msg);
            }
        });
    
        2
  •  0
  •   dzida    14 年前

    只有当你拥有google.com时,你才能做到这一点,我认为这至少是不可能的:(跨域问题)

    为了克服这个问题,你可以发布到你的服务器上,让服务器连接到google.com,然后你可以用从google.com检索到的数据对用户做出响应。

        3
  •  -2
  •   spinon    14 年前

    我会尝试将数据类型设置为HTML,看看是否有帮助。