javascript - how to debug and check values in php which are passed by ajax -


i have function in jquery sends values php file:

$.ajax({ //make ajax request cart_process.php     url: "cart_process.php",     type: "post",     datatype: "json", //expect json value server     data: {          quantity: iqty,          product_code: icode,          color: icolor,          color_code: icolorcode     } }).done(function(data) { //on ajax success     $("#cart-info").html(data.items); //total items in cart-info element     button_content.html('add cart'); //reset button text original text     alert("item added cart!"); //alert user     if ($(".shopping-cart-box").css("display") == "block") { //if cart box still visible         $(".cart-box").trigger("click"); //trigger click update cart box.     } }).fail(function(data) {     alert('failed load') }) 

here ajax request fails reason , shows alert('failed load');. here ajax requesting cart_process.php , sends values in data variable processed in cart_process.php below:

if (isset($_post["quantity"]) && isset($_post["product_code"]) && isset($_post["color"]) && isset($_post["color_code"])) {     $product_code   = filter_var($_post["product_code"], filter_sanitize_string); //product code     $product_qty    = filter_var($_post["quantity"], filter_sanitize_number_int); //product quantity     $color   = filter_var($_post["color"], filter_sanitize_string); //product color     $color_code    = filter_var($_post["color_code"], filter_sanitize_number_int); //product color_code      $product        = array();     $found          = false;     //fetch item database using product code     $statement = $mysqli_conn->prepare("select familyname, productprice productsmaster pid = ? limit 1");     $statement->bind_param('s', $product_code);     $statement->execute();     $statement->bind_result($familyname, $productprice);      while ($statement->fetch()) {         $new_product = array( array('colorname'=> $color, 'name'=> $familyname, 'price'=> $productprice, 'code'=>$product_code, 'qty'=>$product_qty)); //prepare new product         if(isset($_session["products"]))         {             foreach ($_session["products"] $cart_itm)  //loop though items             {                 if($cart_itm["code"] == $product_code && $cart_itm["colorname"] == $color)                 { //if item found in list, update new quantity                     $product[] = array('colorname'=>$color, 'name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$product_qty, 'price'=> $cart_itm["price"]);                     $found = true;                 }                  else                  {                     //else continue other items                     $product[] = array('colorname'=>$cart_itm["colorname"], 'name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=> $cart_itm["price"]);                 }             }              if (!$found)             { //we did not find item, merge new product list                 $_session["products"] = array_merge($product, $new_product);             }              else              {                 $_session["products"] = $product; //create new product list             }         }         else         { //if there's no session variable, create new             $_session["products"] = $new_product;             die(json_encode(array('items'=>1)));         }     }     $total_items = count($_session["products"]); //count items in variable     die(json_encode(array('items'=>$total_items))); //exit script outputing json data } 

i need check why ajax on success not working. how debug or check values in php echo doesn't show on screen?

you can debug browser sources tab , console.


Comments