0

ajaxの可変数のアイテムを更新したい。私が持っているのは

<input name="cart[qty][25]" id="25" value="10" size="4" title="Qty" class="input-text qty">

私のフォームに10個の同様のフィールドがあり、更新する必要のない他のフィールドもたくさんあるとします。

IDがテキストフィールドのIDと等しいカート内のアイテム数量を更新したい。私はそれがPHPで簡単に行うことができることを知っています

if(isset($_POST['update'])){
  foreach($_POST['cart']['qty'] as $k=>$v)
{
  // Do stuff
}

しかし、私はこれを$.postに入れたいです。

jQuery(".update-cart").on('click',function(){
  jQuery(".cart-item").each(function(){
  var  id = jQuery(this).attr('id');
  var qty = jQuery(this).val();
    //What should i do here and on my php file ?
  });
});
4

1 に答える 1

0

Jquery serialize メソッドを試すことができます。

http://docs.jquery.com/Ajax/serialize

アップデート:

jQuery(".update-cart").on('click',function(){
jQuery(".cart-item").each(function(){
 if(jQuery(this).hasClass('qty'))
 {
   var  id = jQuery(this).attr('id');
   var qty = jQuery(this).val();
 }
 //What should i do here and on my php file ?
 });
});

また

jQuery(".update-cart").on('click',function(){
   alert($('.qty').serialize());
});
于 2013-03-04T07:04:11.107 に答える