我通过JS调用API,然后在响应上运行if查询
var myurl = 'https://XXXX.net/api/check?';
var myaccess = 'access_key=XXXX';
var myemail = 'email=XXX@XXX.com';
var pcapi = new XMLHttpRequest();
var myNewURL = myurl + myaccess + '&' + myemail;
pcapi.open("GET", myNewURL, false);
pcapi.send();
var emailStatus = JSON.parse(pcapi.responseText);
var emailStatus = emailStatus.format_valid;
var emailStatus= JSON.stringify(emailStatus);
if emailStatus == 'true'{
alert('Email is correct');
}
else{
alert('Email is incorrect');
}
如果我提醒emailStatus,当电子邮件地址有效时,它会返回“true”。但是当Ii在'if'语句中尝试它时,它在控制台中有一个'意外的标识符'错误。有任何想法吗?
答案 0 :(得分:2)
您的情况必须用括号括起来,如下:
if (emailStatus == 'true') {
alert('Email is correct');
} else {
alert('Email is incorrect');
}