javascript - passing multiple parameters to getJSON creating issues -


i using ajax-json script. new these languages. trying shopping cart example. remove item cart not working. have function below in

js

//remove items cart     $("#shopping-cart-results").on('click', 'a.remove-item', function(e) {         e.preventdefault();           var pcode = $(this).attr("data-code"); //get product code         var pcolorname = $(this).attr("data-color"); //get product color         alert(pcode);         alert(pcolorname);         $(this).parent().fadeout(); //remove item element box         $.getjson( "cart_process.php", {"remove_code":pcode, "remove_color":pcolorname} , function(data){ //get item count server              alert(data);             $("#cart-info").html(data.items); //update item count in cart-info             $(".cart-box").trigger( "click" ); //trigger click on cart-box update items list         });     }); 

in above code, pcode, pcolorname showing proper values , alert(data); showing [object, object] don't know coming right or wrong.

i have product having multiple colors. e.g product1, blue ; product1, red. when added both in shopping cart , clicked on product1, blue remove cart becomes empty should not happen.

cart_process.php having functions show shopping cart, remove item cart. in functions have passed product code , product color name. still not working properly.

cart_process.php code

################## list products in cart ################### if(isset($_post["load_cart"]) && $_post["load_cart"]==1) {     if(isset($_session["products"]) && count($_session["products"])>0){ //if have session variable         $cart_box = '<ul class="cart-products-loaded">';         $total = 0;         foreach($_session["products"] $product){ //loop though items , prepare html content             $cart_box .=  '<li>' . $product["name"].', '.$product["colorname"] .' (qty : ' . $product["qty"]. ') &mdash; ' . $currency. sprintf("%01.2f", ($product["price"] * $product["qty"])). ' <a href="#" class="remove-item" data-code="'.$product["code"].'" data-color="'.$product["colorname"].'">&times;</a></li>';             $subtotal = ($product["price"] * $product["qty"]);             $total = ($total + $subtotal);         }         $cart_box .= "</ul>";         $cart_box .= '<div class="cart-products-total">total : '.$currency.sprintf("%01.2f",$total).' <u><a href="view_cart.php" title="review cart , check-out">check-out</a></u></div>';         die($cart_box); //exit , output content     }else{         die("your cart empty"); //we have empty cart     } }  ################# remove item shopping cart ################ if(isset($_get["remove_code"]) && isset($_get["remove_color"]) && isset($_session["products"])) {     $product_code   = filter_var($_get["remove_code"], filter_sanitize_string); //get product code remove     $prod_color   = filter_var($_get["remove_color"], filter_sanitize_string); //get product color remove     $product = array();     foreach ($_session["products"] $cart_itm) //loop through session array var     {         if($cart_itm["code"]!= $product_code && $cart_itm["colorname"]!= $prod_color){ //item does,t exist in list             $product[] = array('colorname'=>$cart_itm["colorname"], 'name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]);         }         $_session["products"] = $product;     }      $total_items = count($_session["products"]);     die(json_encode(array('items'=>$total_items))); } 

values getjson not passing remove item shopping cart in cart_process.php (in above code). if echo $_get["remove_code"] , $_get["remove_color"] nothing gets displayed. guess call not going whatever echo in if loop nothing gets displayed.

i not able understand making mistake. can please me in this?

if use j query 1.6 or above use

var pcode = $(this).prop("data-code"); //get product code var pcolorname = $(this).prop("data-color"); //get product color 

i hope these you


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -