Directly return Boolean type processing in the javascript background
R recently used jqueyr's ajax background verification to directly return a Boolean value to the foreground and transmit it to the foreground in json format.
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 it directly in code
if(!result){console.log(result);}
No output.
After debugging with firebug, it turns out to be a string, so the following judgment will not be executed in any way.
Well, here we only need to convert the result to the Boolean type. It's easy to think about it!
1. Use Boolean (result); the result is true.
2. Use underscZ labels? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> vcmW1xGlzQm9vbGVhbiy94bn7ysdmYWxzZTxpbWcgYWx0PQ =" cry "src =" http://www.bkjia.com/uploads/allimg/141204/050522IW-1.gif ">
Try another method: first compare it with a string and then judge
Result = "false "? False: true; temporarily solved. Is there any other method? The last thought is that json is used in this example. Use the jquery method to try it.
result = $.parseJSON(result);
if(!result)
{
console.log(result);
}
Perfect solution.