How to stop at ajax request?

How to stop at ajax request?

Hi

I have some code that if I get a "undefined/null" value then it means my code has to actually retrieve these values from a database through an ajax request.

So I had an $.post() and in the callback part I had the variables waiting to be filled. However I noticed while it was doing is request to the server the script kept on going so by the time it came back the script had finished and had tried to use these values(what where undefined still).

So how do you stop the script while it is doing the ajax stuff? Like there are actually cases in my script where the value already exists and I don't need to hit the database so that's why I did not stick everything in the callback part.