检索ajax响应的特定部分并将其放入变量中 [英] retrieve a specific part of the ajax response and put it in a variable
问题描述
我想获得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屋!