input[] Feld über Ajax laden

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • input[] Feld über Ajax laden

    Hallo,
    ich habe hier eine Warenkorb für den ich eine Aktualisierung der Anzahl möglich machen will:

    PHP-Code:
    $("#shopping-cart-results").on('submit''.form-to-update', function(e) {
            
                              
         var 
    productCode = $('input[name="productCode[]"]').serialize();
                    
                    
                    
        var 
    quantity = $('input[name="quantity[]"]').serialize();

         
                      
                $.
    ajax({ 
                    
    url"cart_process.php",
                    
    type"post"
                    
    dataJSON.stringify({  
            
                               
    productCode,
                            
                                
    quantity 
                                 
                                 
    })
                           
                          
                        
                }).
    done();
                
          $(
    "#shopping-cart-results").html('<img src="images/ajax-loader.gif">'); //show loading image
            
    $("#shopping-cart-results" ).load"cart_process.php", {"load_cart":"1"});
          
                
    e.preventDefault();
            }); 

    das FormularArray wird auch über ajax geladen:

    PHP-Code:
    if(isset($_POST["load_cart"]) && $_POST["load_cart"]==1)
    {

          if(isset(
    $_SESSION["products"]) && count($_SESSION["products"])>0){ //if we have session variable
            
    $cart_box '<form class="form-to-update"><ul class="cart-products-loaded">';
            
    $total 0;
            foreach(
    $_SESSION["products"] as $product){ //loop though items and prepare html content
                
                //set variables to use them in HTML content below
                
    $product_name $product["product_name"]; 
                
    $product_price $product["product_price"];
                
    $product_code $product["product_code"];
                
    $product_qty $product["qty"];
                
                
    $cart_box .=  "<li><span>Ihr Produkt: $product_name </span><span>PS: $product_code <input type=\"hidden\" name=\"productCode[]\" value=\"".$product_code."\" /></span> <span>Anzahl : <input type=\"text\" name=\"quantity[]\" value=\"".$product_qty."\" style=\"width: 30px;\" /></span><span>Einzelpreis :$currency ".sprintf("%01.2f"$product_price)." </span> <span>Zwischensumme: $currency ".sprintf("%01.2f", ($product_price $product_qty)). "</span> <span><a href=\"#\" class=\"remove-item\" data-code=\"".trim($product_code)."\"><img src=\"./themes/shop/images/trash.png\" border=\"0\" /></a></span></li>";
                
    $subtotal = ($product_price $product_qty);
                
    $total = ($total $subtotal);
            }
        
            
    $cart_box .= "</ul>";
            
    $cart_box .= '<div class="clearfix"></div><div class="cart-products-total">Total : '.$currency.sprintf("%01.2f",$total).' <button type="submit" class="warenkorb-aktualisieren">aktualisieren</button></form> <a href="https://www.vah.de/shop/zur-kasse" title="zur Kasse">zur Kasse</a></div>';
            die(
    $cart_box); //exit and output content
        
    }else{
            die(
    "<div class='empty'>Ihr Warenkorb ist leer</div>"); //we have empty cart
        
    }

    Nun wird leider immer nur FormularArray mit dem letzten Wert von productCode weitergegeben:

    PHP-Code:
    // cart_process.php

    if(isset($_POST) AND is_array($_POST['productCode'])) {
                                   
           foreach(
    $_POST['productCode'] as $key => $value) {

                                              
            if(isset(
    $_SESSION["products"])){ 
                           
                    
    $_SESSION["products"][$value]['qty'] = $_POST['quantity'][$key]; //unset old item
                            
            
    }
            
       } 
    Ich komme da nicht weiter. Vielleicht weiß jemand eine Lösung.

  • #2
    Und die productCode-Variable im ersten Abschnitt enthält was?
    I don't believe in rebirth. Actually, I never did in my whole lives.

    Kommentar


    • #3
      habs gelöst

      PHP-Code:
      $("#shopping-cart-results").on('submit''.form-to-update', function(e) {
              
          
                 
       var 
      form_data = $(this).serialize();    
                        
      alert(form_data); 
                  $.
      ajax({ 
                      
      url"cart_process.php",
                      
      type"post",
              
                      
      dataType:"json",        
       
                      
      dataform_data
                                   
                             
                              
      // other data
                          
                  
      });
                  
            $(
      "#shopping-cart-results").html('<img src="images/ajax-loader.gif">'); //show loading image
              
      $("#shopping-cart-results" ).load"cart_process.php", {"load_cart":"1"});
            
                  
      e.preventDefault();
              }); 

      Kommentar

      Lädt...
      X