且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用jQuery / ajax从外部网站获取特定元素

更新时间:2023-02-23 20:29:04

在你的原始成功回调中你从responseText获取你的html内容,你应该在第二种情况下:

In your original success callback you're fetching your html contents from responseText, you should do the same in the second case:

   success: function(res) {
      $(res.responseText).find('div.content').each(function(){
          $('#here').append($(this).html());
     });

使用class =content或id应该可以工作。但是,您应该知道上面的代码将所有具有类内容的 div 添加到您的id =herediv中,这可能不是您想要的。如果只想查看特定元素的内容,请改用 id

Using class="content" or id should work. However, you should be aware that the code above adds all div's that have class content to your id="here" div, which might not be what you want. If you want just the contents of a specific element, use its id instead.