2012-06-25 39 views
-2

我试图抓住所有的ID所PART_NUMBER并在同一时间给他们1到我的Ajax调用:JQuery的每个选择Ajax调用

单个项目的HTML如下:

<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> 

这里是我的jQuery的是在。每个换行:

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

有人能指出我这是为什么在每一行打破?我是否也正确地在ajax调用中正确调用“部件”?

+1

问题是... – zerkms

+0

'.attr('part_number')'?你的意思是'.attr('id')'是'part_number'吗? – undefined

+0

我不认为你正确地在数据参数中包含数组。 'parts'是一个数组,而不是一个字符串。如果它在每一行都打破了,你应该有一个javascript错误。它是什么? –

回答

1

如果你的意思是有这个标记:但是

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

注意,:

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

你想进去与id="part_number"元素的文本,那么你应该做这样的,在ID选择器上调用.each()是没有意义的,因为您的假定只有一个具有任何特定ID的元素。

+0

任何建议更好的方式来格式化HTML? –

+0

改为使用班级。 '

'。选择使用'$('。part_number')'。 –

+0

有很多“项目”我只是以1为例 –