Friday, February 27, 2009

[jQuery] function $.ajax return true/false ?

Hello
I have the following code:

function pnrexists(a){
$.ajax({
url: '/inc/chkusr.php?q=p',
type: 'POST',
dataType: 'html',
data: {'pnr': a},
timeout: 2000,
success: function(data) {
if(data==1){
alert('true');
return true;
}else{
alert('false');
return false;
}
},
});
}


the code above is triggered by:


$.validator.addMethod("pnrcheck", function(ph, element) {
alert('1');
if(persnr(ph)) {
alert('2');
if(pnrexists(ph)) {
alert('3');
the code continues..but noting to show...


The problem is: I see:
alert 1
alert 2
alert true
but NOT alert 3?? Why?

No comments: