Try setting async to false: ( See edit below )
$.ajax({ type: "POST", async: false, url: "/webservice/user.asmx/CheckForm", data: "{'type':'" + var_type + "', 'value':'" + var_value + "'}", contentType: "application/json; charset=utf-8", dataType: "json", error: function (XMLHttpRequest, textStatus, errorThrown) { }, success: function (data) { var obj = data.d; } });
This will block the AJAX call, so the browser will wait for it to complete before continuing. Of course, I'm still not sure how this relates to a boolean being checked in the parent conditional expression. Maybe there is a code that you donβt show us ...
Edit:: sigh: I was young and stupid when I posted this answer and actually forgot everything about it. I keep the above information unchanged for historical purposes (since it seems to have helped some people, or at least they think it is), but understand that this is not the right approach .
Making synchronous and blocking asynchronous calls is wrong in every way. Do not do this. Instead, structure your logic to respond to asynchronous operations. In the case of this question, console.log() calls should be executed in the success (or error) handler of the AJAX call, and not in the code after calling this call.
David
source share