jQuery AJAX .post pulling multiple variables from one php -


i trying find best way pull multiple variables php ajax post. right now, using .substr split echoed variable php itself.

here's ajax post (with jquery)

$.post("scripts/enter/register.php", {username : username, email : email, password : password}, function(data) {     var callback = data.substr(0,1);     var user_session = data.substr(1);     if(callback === "1"){         //do registration script     } else {         //give error     } }); 

and php

if (strlen($hash) >= 20) {     if($user_name){         //perform sql queries         echo "1";         echo $cookie;     } else {         echo "0";     } } else {     echo "0"; } 

as see, in php, echo 2 variables when goes well. when there's error, echo 1 variable. script works fine, find clunky , apparently unsecure. on side note, have come understand echo not secure, though no 1 has told me instead.

i have script handles login (this last script register), use different php script. here questions:

  1. can combine both register , login (and other php scripts) single script?
  2. is there better way turn php variables javascript variables able use in jquery?

you have if(callback === "1"){ in code.

this should if(callback == "1"){ assuming may number string

that may solve part of problem


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -