同步AJAX呼叫

In a scenario, I have written a javascript and in middle of the script I made an AJAX call. There is some more amount of script which is present after the AJAX call and this needs to be executed based on the results returned from the function. But Unfortunately the script which is present after the AJAX call is executed before the function call itself, that is, the call is being made asynchronously. Could anyone please suggest me how to overcome this problem?

Thanks in Advance..

Are you using jQuery? IF not, you should :) Then you should read this documentation - http://api.jquery.com/jQuery.ajax/ And put the rest of the script in the success handler of the ajax function.

If you still insist on not using jQuery, just use the onreadystatechange function http://www.w3schools.com/ajax/ajax_xmlhttprequest_onreadystatechange.asp