从< title>检索文字元素来自< head>在ajax响应 [英] Retrieving text from the <title> element from the <head> in an ajax response

查看:64
本文介绍了从< title>检索文字元素来自< head>在ajax响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我很确定这个问题已经得到解答,我已经想出了如何从这里,但是当用ajax尝试这个时,FireBug响应与未定义 jQuery('title',data).text()

  // Ajax下一页
函数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 ',data).text());
jQuery('title')。text(jQuery('title',data).text());
}
});
}

更新
$ b

成功:函数(数据){} 中的数据变量似乎包含 header / title 元素,但 .text()似乎无法访问,尽管 jQuery 'title',data)带有 [object Object] (所以 object 本身似乎是可访问的,内容不是)。



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



Object <$来自 data 的code> title


我猜你可能需要这个:

  var url ='http://google.com'; 
$ .get(get_url.php?url =+ url,function(response){
var title =(/< title>(。*?)< \ / title> / m).exec(response)[1];
});


so I'm pretty sure this question has been answered and I've figured out how to retrieve the text out a <title> element as stated here, but when attempting this with ajax, FireBug responds with undefined with 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());
        }
    });
}

Update

The data variable from success: function(data){} seems to contain the header/title elements, but the .text() seems to be inaccessible although the jQuery('title', data) comes back with [object Object] (so the object itself seems to be accessible, the contents is not).

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

Object title from data

datatye http://iforce.co.nz/i/lw0yrcmh.z1z.png

解决方案

I guess you might need this:

var url = 'http://google.com';
$.get("get_url.php?url="+url,function(response) {
    var title=(/<title>(.*?)<\/title>/m).exec(response)[1];
});

这篇关于从&lt; title&gt;检索文字元素来自&lt; head&gt;在ajax响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆