在AJAX中传递布尔值

I'm trying to pass boolean variables from the server to the client in AJAX. I found this solution on stackoverflow:

You want to distinguish between "real" booleans and the texts "true" and "false"?

Well - an attribute might help you - e.g. IsActive.

For "text":

<problem>false</problem> 

For booleans:

<problem IsActive="false"></problem>

Now my question is simple: how do I read back the IsActive attribute in javascript? I'd imagine it would be something along the lines of:

var problem = xmlResponse.getElementsByTagName("problem")[0];
var IsActive = problem.getAttribute("IsActive");

but what's the exact code for getting that to work?

Much obliged.

If you're using XML, use what's called a boolean attribute, true is when the attribute exists, and false is when it doesn't exist. I assume you're not using any JS libs like jQuery or prototype.

You can then simply use the hasAttribute method on the dom node:

XML

<problem IsActive>foo</problem>
-or-
<problem IsActive="IsActive">foo</problem>

JS

var problem = xmlResponse.getElementsByTagName('problem')[0];
var IsActive = problem.hasAttribute('IsActive');

AFAIK most "AJAX" these days uses JSON, which makes data passing significantly easier.