jquery - How can I echo a message and return a code to AJAX from PHP -


all,

i have ajax function, calls php url through html data type. cannot use other datatypes ajax requests due server constraints. trying print message , handle scenarios based on return code. following code doesn't seem work. can advise?

here's simple ajax call:

 $.ajax({ type: "post", url: "validateuser.php", datatype: html, success: function(msg, errorcode){ if(errorcode == 10) { callafunction(); } else if(errorcode == 20) { callsomething(); } else { dosomethingelse(); } } }); php code: --------- <?php function validateuser() { $username = 'xyz'; if (!empty($username) && strlen($username)>5) { echo 'user validated'; return 10; } else if (empty($username)) { echo 'improper username'; return 20; } else if (strlen($username)<5) { echo 'username length should atleast 5 characters'; return 30; } exit; } ?> 

thanks

your php function. not being called.

also, not sending data php file.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -