Whatever code you have that uses "b" needs to go in the success event also, or put it in a function that the success event code calls.
success: function (result) {
b = true;
process(b);
},
function process(result){
if (result){
}
}
Your ajax call is asynchronous so your code doesn't halt at the $.ajax line, it continues on to the code after while the ajax call completed in the background. The cheaper alternative is to leave your code as it is and make the ajax call synchronous rather than asynchronous by adding
async: false
to the options.
jQuery.ajax() | jQuery API Documentation[
^]