所以我很确定这个问题已经得到解答了,我已经找到了如何从<title>
元素中检索undefined
元素,但是当用ajax尝试这个时,FireBug会响应jQuery('title', data).text()
与//Ajax the next page
function grab_NextPage(){
var NextPgElement = jQuery('.swipe_arrow.right');
var NextPage = NextPgElement.find('a').attr('href');
jQuery('.swipe_arrow.right').children('a').addClass('hover');
jQuery.ajax({
url: NextPage,
dataType: "html",
success: function(data){
console.log(jQuery('title', data).text());
jQuery('title').text(jQuery('title', data).text());
}
});
}
。
data
更新
来自success: function(data){}
的{{1}}变量似乎包含header/title
元素,但.text()
似乎无法访问,尽管jQuery('title', data)
带有{[object Object]
1}}(所以object
本身似乎是可访问的,内容不是。)
title
的答案 0 :(得分:1)
我想你可能需要这个:
var url = 'http://google.com';
$.get("get_url.php?url="+url,function(response) {
var title=(/<title>(.*?)<\/title>/m).exec(response)[1];
});
答案 1 :(得分:1)
可以使用filter()
获取title
代码
success: function(data){
console.log($(data).filter('title').text());
}