user357034
user357034

Reputation: 10981

retrieve a specific part of the ajax response and put it in a variable

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);
        } 
    }) 
}); 
}); 

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>

Upvotes: 0

Views: 3077

Answers (1)

Dutchie432
Dutchie432

Reputation: 29160

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?

Upvotes: 1

Related Questions