Question : separator alternative (PHP and AJAX)

When the passwordconfirmation field is typed, I want not only to tell the user if password and passwordconfirmation are equal, but also tell the user if the email is in database. Right now, I am thinking about echoing one responseText with a separator (the vertical bar). I am thinking about data like "| || | || | || | | || | || |" happening next. What are the alternatives to a separator? For example, is there a way to echo an array???

Answer : separator alternative (PHP and AJAX)

HI,

Its not good to use your own separator in the response text. The best solution for this is to use JSON. json_encode() function will serialize your array and give you the JSON string.

$arr = array ('a'=>'some text','b'=>2,'c'=>3,'d'=>4,'e'=>5);
echo json_encode($arr);
?>

Then convert this  JSON string to  JSON object using Javascript eval() function.

var JSONObj= eval('(' + responseText + ')');

then to access value of 'a' use the below syntax

JSONObj.a






Random Solutions  
 
programming4us programming4us