R Recently used Jqueyr Ajax background verification to return a Boolean value directly to the foreground, using JSON format to upload to the foreground
var result = $.ajax ({url: '/' +window.location[' pathname '].split ('/') [1]+ '/resourceprivate/validateresourceprivate? Rid= ' +rid,async:false,datatype: "JSON"}). ResponseText;
Console.log (result);
The result is false.
Use directly in your code
if (!result) {console.log (result);}
There has been no output.
After debugging using Firebug, it turns out to be a string, so the following judgment will not be executed anyway.
All right, here we go. Just convert the result to a Boolean type, it's easy to think!
1. Use Boolean (result); The result is true
2. Using underscore's isboolean, the result is false
Another way to think about it: First use a string comparison and then judge
result = result== "false"? False:true;for the time being, is there any other way out? Finally, I think, this is using JSON, then use the jquery method to try
<pre code_snippet_id= "537953" snippet_file_name= "blog_20141201_4_5931945" name= "code" class= "JavaScript" > result = $.parsejson (result);
if (!result)
{
Console.log (result);
}
Perfect solution.
JavaScript backend directly returns Boolean type processing