[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

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???
1 Solution

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!

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now