working with dhtmlxAjax.get(...

Hello,

I’m trying to get true/false returned while using dhtmlxAjax but can’t find how to…

Here’s my sample code :

[code]checkMember= hasBooks(Id);

function outputResponse(loader) {
response = loader.xmlDoc.responseText;
if (response == ‘1’) { // 1 means Member has at least one book
return true;
} else { // 0 means Member doesn’t have any book
return false;
}
}

function hasBooks(Id) {
var url = “class/members.php?id=”+Id;
dhtmlxAjax.get( url, outputResponse );
}[/code]

The idea (of course) is that checkmember should have true or false values.

But here, it is “undefined”… :confused:

By default ajax call is async, which means - you can’t use result of remote script as result of js function ( you can get it through callback )

The simplest solution would be to use sync ajax reqest

function hasBooks(Id) { var url = "class/members.php?id="+Id; return dhtmlxAjax.getSync( url ).xmlDoc.responseText == "1"; }

Thanks Stanislav,
It works fine with your code.
Bye