-2

I am trying to grab all the id's that are part_number and feed them 1 at a time into my ajax call:

The html for a single item looks like this:

<div class="item">
    <p class="image"><a onmousedown="return SearchSpring.Catalog.intellisuggest(this, 'eJyzNCvJT8thcDRwNDG2NDTXNXR1MdI1sTR21bW0NDDQdXa1cDI2cTE0d3RxY2AwBENjAwZzMyOG9KLMFAC61g1R', 'd1f18f7e3b14f73ded97ff0a97db67a2eb19b128322804efbe2f46bd5fcd3c1f')" href="http://208.69.47.49/ProductSearch/ProductDetail.aspx?ID=KEL-AF24-SR"><img onerror="this.onerror=null;this.src='//d1qhbfo7yqnkif.cloudfront.net/ajax_search/img/missing-image-75x75.gif';" src="//208.69.47.49/Contents/Images/PART18_100PX.GIF"></a></p>
    <p class="name"><a onmousedown="return SearchSpring.Catalog.intellisuggest(this, 'eJyzNCvJT8thcDRwNDG2NDTXNXR1MdI1sTR21bW0NDDQdXa1cDI2cTE0d3RxY2AwBENjAwZzMyOG9KLMFAC61g1R', 'd1f18f7e3b14f73ded97ff0a97db67a2eb19b128322804efbe2f46bd5fcd3c1f')" href="http://208.69.47.49/ProductSearch/ProductDetail.aspx?ID=KEL-AF24-SR">VM2327T23A00T</a></p>
    <p class="price">$388.00</p>
         <p id="part_number">VM2327T23A00T</p>
</div>

Here is my Jquery that is breaking on the .each line:

var parts = [];
var listPrices = [];
SearchSpring.jQuery('id').each(function () {
    parts.push(SearchSpring.jQuery(this).attr('part_number'));
    //listPrices.push(SearchSpring.jQuery(this).attr('list_price_baan'));
});
//skus = skus.join(',');
SearchSpring.jQuery.ajax({
    type: "POST",
    url: "RealTimePricing.aspx/GetCustomerPrice",
    data: "{partNumber:' " + parts + "', listPrice: ' " + listPrices + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    async: true,
    cache: false,
    success: function (data) {
        for (var id in data) {
            var prices = data[id]['prices'];
            SearchSpring.jQuery('#' + id).text(prices);
        }
    }
});

Can someone point me to why this is breaking at the each line? Also am I calling the "parts" correctly 1 at a time in the ajax call?

4

1 回答 1

1

If what you mean is given this markup:

<p id="part_number">VM2327T23A00T</p>

You want to get the text inside elements with id="part_number", then you should be doing it like this:

$('#part_number').each(function () {
    var text_inside = $(this).text();
    // shove that into an AJAX call
});

Note, however, that it doesn't make sense to call .each() on an ID selector, because you're supposed to have only one element with any specific ID.

于 2012-06-25T21:38:25.737 回答