hi, i have this code $.post(home_link + '/register/', { 'username': $('input[name=username]').val(), }, function(data){ alert(data); }, 'json'); alert('1'); HTML: why i get alert 1 before alert data
I'm assuming that it is because the request is 'asynchronous' which means code will continue to execute until a response is received, when a response is received your alert(data); code will be executed. I don't use jQUery so I am not sure of how you can fix this issue or if I'm correct.. just an educated guess. AJAX - Asynchronous Javascript And XML
...... function(data) { alert(data); alert('1'); } ...... Code (markup): I would say that the function is performed once the data has been loaded. try the above. You can put as much code within that function as you want, it doesn't have to be only one line.
I will try to clarify this further. The $post part of your script is sending data to another page on your server and waiting for a response. Because it is an asynchronous request, all other code will continue executing until a response is received (all other code being your alert('1')). Once a response is received THEN your alert(data); code will be executed...
$.post is ajax send data in json and wait the output i understand now what you are mean thanks camjohnson95