繁体   English   中英

使用jQuery.get()从另一个页面加载内容

[英]Using jQuery.get() to load content from another page

我正在尝试提出一个请求,以从另一页面加载内容,然后搜索该内容并提取所需的信息。 我一直在尝试使用jQuery.get()来执行此操作,但无法使其正常工作。

这是我正在使用的代码:

$.get('/category/page-2/', function(data) {
  var theContent = $(data).find('#newWrapper img').attr('src');
  theContent.appendTo('#container'); // this isn't inserting the url string

  console.log('the content: ' + theContent); // theContent returns undefined
}, 'html');

我使jQuery.load()工作,但是我需要从返回的文档中获取多个信息,并且不想为每个请求都发出请求。 这工作正常:

$( ".related-product" ).eq(0).load( "/category/page-2/ #newWrapper img" );

尝试这个

jQuery.get('/category/page-2/',
{
    ajax: true
}, function (data) {
    data = jQuery(data);
    var theContent = jQuery('#newWrapper img', data).attr('src');
    theContent.appendTo('#container'); // this isn't inserting the url string
    console.log('the content: ' + theContent); // theContent returns undefined

});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM