1

HTMLコード

      <form id="product_form" action="" method="post">
        <input type="hidden" name="wpsc_ajax_action" value="add_to_cart">
        <input type="hidden" name="product_id" value="8191">
        <div class="current-items">
        <div id="903" class="wpsc_select_variation">
        <div id="902" class="wpsc_select_variation">
        <div id="903" class="wpsc_select_variation">
        <div id="875" class="wpsc_select_variation">
        </div>
   </form>

jQUERYコード

    jQuery("#product_form").live('submit', function(){


    $wpsc_select_variation= $(".current-items > div").attr("id");
    $wpsc_ajax_action = $("input[name='wpsc_ajax_action']").val();
    $product_id = $("input[name='product_id']").val();

    form_values = 'variation[480]='+$wpsc_select_variation+'&wpsc_ajax_action='+$wpsc_ajax_action+'&product_id='+$product_id;


     jQuery.ajax({
         type:"POST",
         url: "wp/products-page/500ml-600ml-colours/krink-k750/index.php?ajax=true",
         data:form_values ,
         success: function(returned_data){
         //$("#response").html(data);

            eval(returned_data);
             jQuery('div.wpsc_loading_animation').css('visibility', 'hidden');

             if(jQuery('#fancy_notification') != null) {
                 jQuery('#loading_animation').css("display", 'none');
             //jQuery('#fancy_notificationimage').css("display", 'none');
             }
         }
     });
     return false;


 });

.current-itemsクラスdiv内に4つの子divがある場合、4つのAjaxリクエストを送信し、このコード行のすべてのループで子クラスの異なるIDを渡します。

             $wpsc_select_variation= $(".current-items > div").attr("id");

コードは1つのrequertで機能しています

したがって、plzは、.current-itemsクラスdiv内の子divに基づいてjqueryベースでループを作成するのに役立ちます

4

1 に答える 1

2

ajaxリクエストを内にラップし.each()ます。

$(".current-items > div").each(function(){
  //ajax call.
  $wpsc_select_variation= $(this).attr("id");
  //after work done as asked in comment add below code.

  $(this).remove(); //to hide use $(this).hide();
});
于 2013-03-15T09:02:00.013 に答える