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???
locke1994Asked:
Who is Participating?
 
palanee83Commented:
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.

<?php
$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






0
 
locke1994Author Commented:
Man, thank you so much, that's exactly what I was looking for!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.