从&lt; head&gt;中检索<title>元素中的文本在ajax回复中</title>

时间:2013-04-09 00:09:43

标签: jquery html ajax

所以我很确定这个问题已经得到解答了,我已经找到了如何从<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本身似乎是可访问的,内容不是。)

here

来自title

对象data

data http://iforce.co.nz/i/rm31s1fg.v31.png

2 个答案:

答案 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());

}