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???
Who is Participating?

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


locke1994Author Commented:
Man, thank you so much, that's exactly what I was looking for!
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.