Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ajax jquery下载页面内容_Jquery_Ajax - Fatal编程技术网

使用ajax jquery下载页面内容

使用ajax jquery下载页面内容,jquery,ajax,Jquery,Ajax,您好, 如何使用ajax和jquery下载一些页面内容: 我正在做类似的事情(一个脚本中包含两个版本): 但是它不会返回任何内容您不能使用AJAX下载网页内容,因为AJAX与承载此脚本的域不在同一域中。另外,.ajax函数调用中存在语法错误。应该是这样的: $.ajax({ url: 'http://yourdomain.com/page1.htm', success: function(data) { $("result").html(data);

您好, 如何使用ajax和jquery下载一些页面内容: 我正在做类似的事情(一个脚本中包含两个版本):

但是它不会返回任何内容

您不能使用AJAX下载网页内容,因为AJAX与承载此脚本的域不在同一域中。另外,
.ajax
函数调用中存在语法错误。应该是这样的:

$.ajax({
    url: 'http://yourdomain.com/page1.htm',
    success: function(data) {
        $("result").html(data);
        alert('Load was performed.');
        var url = 'http://yourdomain.com/page2.htm';
        $('div#result').load(url);
    }
});

虽然无法从Javascript直接查询当前域外部的主机,但可以使用代理脚本检索所需的数据

使用jQuery进行跨域AJAX查询:

您还可以使用flXHR脚本,该脚本可以放入许多Javascript库(包括jQuery)


flXHR:

您也可以简单地调用一个PHP/ASP/RUby页面,该页面反过来为您进行外部调用,并以您需要的方式显示信息

1.  PAGE --> PHP --> External web
        (Ajax)

2.  PAGE <-- PHP <-- External web
      (callback)
1。页面-->PHP-->外部web
(阿贾克斯)

2.PAGE您可以使用YQL代理您的呼叫:

$.ajax({
  url:"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'http://www.google.com'&format=xml&callback=callback",
  type: 'GET',
  dataType: 'jsonp'
});

  function callback(data){
    $('#result').html(data.results[0]);
  }

您需要使用一种称为JSONP的东西来跨越域。Seider提供了更多关于如何使用jQuery实现这一点的详细信息。

放下它,使用jQuery!哦,等等……有什么办法吗?要获取其他页面的内容?您可以在iFrame中显示其他页面的内容,但您也不能访问/读取它。请看我的答案-它提供了两种方法来检索当前域外部的数据。我得到了一个空白页面。
$.ajax({
  url:"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'http://www.google.com'&format=xml&callback=callback",
  type: 'GET',
  dataType: 'jsonp'
});

  function callback(data){
    $('#result').html(data.results[0]);
  }