我想提出一个请求,从另一个页面加载内容,然后搜索该内容并提取我需要的信息。我一直试图使用jQuery.get()来做到这一点,但不能得到它的工作。使用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");
是什么'data'的价值?你确定元素'#newWrapper img''存在'data'中吗?也''theContent'不是一个jQuery对象,你可以调用'theContent.appendTo()' –
你可以做'console.log(data)'并在这里发布 –
最后不要使用HTML,最好使用json –