2013-04-12 26 views
5
$.ajax({ 
    type: "POST", 
    url: 'ajax_subtotal.php', 
    data: listing_id=listId, 
    dataType:'json', 
    success: function(data) 
    { 
     if(data['result']=='success') 
     { 
      alert(data['pricing']); 
     } 
} 

data['pricing'] मुझे एक उत्पाद की कीमत देता है .. यदि उत्पाद मात्रा बदल जाती है तो फ़ंक्शन कॉल कर रहा है। तो, मैं एक ही समय में एकाधिक उत्पादों की कुल कीमत की गणना कैसे कर सकता हूं ??मैं जावास्क्रिप्ट में एकाधिक उत्पादों की कुल राशि की गणना कैसे कर सकता हूं? मूल्य AJAX

+0

संपूर्ण वस्तु को देखने के बिना, यह क्या किया जाना चाहिए पर अनुमान लगा पाना कठिन हो जाएगा। – Daedalus

+0

अधिक जानकारी प्रदान करें। वर्तमान में अप्रत्याशित। –

+0

आपने ब्रैकेट को ठीक से बंद नहीं किया ...! –

उत्तर

4
First i store all the value in to the hidden field.. 

<input type="hidden" name="NumberOfProperty[]" id="NumberOfPropertyTxt<?php echo $id;?>" value=""/> 

When my ajax is calling i got all the value in it.. 

var values=$('input[name="NumberOfProperty[]"]').map(function() 
{ 
return this.value 
}).get(); 
console.log(values); 

In this i got my all price stored in to the array...then 

var Total=0; 
         $('input[name="NumberOfProperty[]"]').each(function() 
{ 
if($(this).val()>0) 
{ 
Total+= parseFloat($(this).val()); 
} 
}); 
$('#sub_total').val(Total); 
$('#subtotal').html(Total); 

I got all the value into the Total and assign it in to the sub_total id.  
2
First you have declare 
var total = 0 
$.ajax({ 
... 
success:function(){ 
    if(data['result']=='success') 
     { 
      total += data['pricing']; 
     } 
    } 
}); 

atlast of the function alert(total); 
संबंधित मुद्दे