我有这样的代码来获取变量 isItemLocked 的值。
function authorItem(itemNumber){
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
url ="Some URL";
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
var isItemLocked = xmlhttp.responseText;
if(isItemLocked){
alert('Item has been Closed.Click OK to go to Search Page');
window.location = "SOME OTHER URL";
}else{
var url ="SOME OTHE URL 1";
location.href = url;
}
}
}
}
isItemLocked 的返回布尔值 true。但是每次我要访问其他一些 URL 时。有什么解决方案吗?
xmlhttp.responseText
不返回布尔值,它返回一个字符串"false"
is true
.
执行字符串比较。
if (isItemLocked === 'true') {
// Do one thing
} else if (isItemLocked === 'false') {
// Do a different thing
} else {
// You have an unexpected response from the server and should handle the error
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)