以下代码无法在else语句下获得正确的响应:
function ajax_response(){
if(is_user_logged_in() && check_key() ){
$result = $do_something;
if($result){
ajax_response_string(1,'success!');
}else{
ajax_response_string(-1,'there is a problem, please try again!');
}
}else{
ajax_response_string(-1,'you must login first.');
}
}
当我注销并尝试单击触发此ajax函数的链接时,我收到“未定义”的响应,它应该是“您必须先登录”。哪里出错了?
答案 0 :(得分:1)
我只是想出来了 - 这不是else语句,它是ajax响应url不适用于已注销的用户。所以,我的问题不再有效了。如有必要请关闭它。
答案 1 :(得分:0)
您在第$result= //do something
行遇到语法错误,因为此行未终止。试试这个:
function ajax_response()
{
if(is_user_logged_in() && check_key() )
{
$result = doSomething; //error was here as there was no line terminator (;) present.
if($result)
{
ajax_response_string(1,'success!');
}
else
{
ajax_response_string(-1,'there is a problem, please try again!');
}
}
else
{
ajax_response_string(-1,'you must login first.');
}
}