Can you please tell me how to correctly return data from a php handler for ajax requests? And how to write this handler in general? I admit, always just returning data via echo , but something tells me that this is not quite correct.
Here is an example:
$.ajax({ type:"POST", url:"../lib/ajax.php", data: {send:act, login:login, password:password}, cache: false, success: function(reply){ alert(reply); if(reply == 'true'){ $('.login-status').text('Ok'); $('.login-status').fadeTo(0, 1); $('.login-status').fadeTo(4000, 0); $('[name = login]').val(''); $('[name = password]').val(''); } } }) Handler:
if(isset($_POST['login'])){ $login = $POST_['login']; $password = $POST_['password']; ... echo 'true'; } }
echoafter all works and even, it seems as, is not a crutch. - Regentecho, but somehow they do it differently. - withoutname