如何从不同的网页与AJAX获得一个div的HTML?不同、网页、AJAX、div

2023-09-10 13:42:40 作者:£龙魔★霸舞彡

我怎样才能得到它位于不同的站点有一定的HTML元素的HTML?

解决方法:

  $。阿贾克斯({
网址:somefile.html,
成功:功能(数据){
    数据= $(数据).find('#DIV ID');
    $('#mydiv')的HTML(数据)。
    警报(完成。);
 }
});
 

解决方案

请一个AJAX调用到PHP或任何其他文件,使用卷曲或其他工具来抓住你想要的网页,并提取div和呼应它,然后当你回来的HTML只是把它一个div里面你的页面

  $。阿贾克斯({
    网址:somefile.html,
    成功:功能(数据){
                    数据= $(数据).find('#DIV ID');
        $('#mydiv')的HTML(数据)。
        警报(完成。);
     }
    });
 
技术问答 OSCHINA

How can I get the html of a certain html element which is located on a different site?

Solution:

$.ajax({
url: 'somefile.html',
success: function(data) {
    data=$(data).find('div#id');
    $('#mydiv').html(data);
    alert('Done.');
 }
});

解决方案

Make a ajax call to a php or any other file , use CURL or other tools to grab the page you want and extract the div and echo it and then when you get back the html just put it inside a div in your page

    $.ajax({
    url: 'somefile.html',
    success: function(data) {
                    data=$(data).find('div#id');
        $('#mydiv').html(data);
        alert('Done.');
     }
    });