检索ajax响应的特定部分并将其放入变量中 [英] retrieve a specific part of the ajax response and put it in a variable

查看:86
本文介绍了检索ajax响应的特定部分并将其放入变量中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得Ajax响应的特定部分,并将此文本放入变量中.在这种情况下,var号.当我使用此代码时,警报显示为空.

I would like to get a particular part of the Ajax response and put this text in a variable. In this case var number. When I use this code the alert comes up null.

jQuery(function(){
jQuery('a.productnamecolor.colors_productname').each(function(){
var star_link = jQuery(this).attr('href');
    jQuery.ajax({
    url: star_link,
    type: 'POST',
    cache: false,
    success: function(data){
        var number = $(data).find("#pt691").text();
        alert(number);
        } 
    }) 
}); 
}); 

以下只是返回的总响应的一小部分.我想在跨度ID pt691中捕获"2",并将其放在变量号中. .text()在这种情况下不起作用吗?

Below is just a small portion of the total response that is returned. I want to capture the "2" in the span id pt691 and put that in the variable number. Does .text() not work in this case?

<span class="PageText_L691n">Based on <span id="pt691">2</span> reviews </span>

推荐答案

对于我来说似乎可以正常运行 http://jsfiddle.net/K7VBp/1/,我可以使用.text().html()取得同样的成功.我们可以看到您的data变量的完整结果吗?

Seems to work OK for me http://jsfiddle.net/K7VBp/1/ and I can use .text() or .html() with equal success. Can we see the full result of your data variable?

这篇关于检索ajax响应的特定部分并将其放入变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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