php - jquery ajax call returning more than a single word -


i'm using following code use return php

if (isset($_post['p_id'])) {     if (!isset($_session['carted_products'])) {         $_session['carted_products'] = array();     }//end if not set products array in session      if (!in_array($_post['p_id'], $_session['carted_products'])) {         array_push($_session['carted_products'], $_post['p_id']);         echo "success";     }//end if not in array     else {         echo "already_added";     } }//end if not set post value else {     echo "fail"; }//end else 

now in jquery part of calling page. use

$.post(     "add_to_cart.php",     {p_id:"<?php echo $row['p_id'] ?>"},     function(responsetext){         //if(responsetext === "success"){         //things on success     } 

but if won't return true.

now when check index of "already_added" in responsetext returns 6..

why happening.

there white spaces in response, try trimming it.

if($.trim(responsetext) === "success"){ 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -