使用Jquery的.load()函数时如何返回状态?

时间:2011-08-31 14:34:30

标签: php jquery

我在我的控制器中有这个动作

public function actionInsertComment()
{
        if (isset($_POST['liga']))
        {

            if(condition)
            {           
                $status = "success";
            }
            else
            {
                $status = "error";
            }

            $this->renderPartial('ligaWallMessages');
        }
}

我正在以下列方式使用JQuery的加载函数:

$('#div_wall_messages').load('insertComment',{comment: comment, liga:idLiga},function(response, status, xhr){
            attachHandlers();
});

在这个例子中,我以一种我不知道的方式设置状态变量(在控制器中)。我读了this link,我知道有状态的预定义值; “success”,“notmodified”,“error”,“timeout”或“parsererror”。

我想知道是否有手动设置状态变量或者我是否可以以其他方式返回变量。

2 个答案:

答案 0 :(得分:0)

无论您从服务器发送什么内容,都可以在status字段中获取response。你为什么要那样做?我认为不可能。

答案 1 :(得分:0)

您可以使用$.post()方法将数据发送到服务器并获取状态响应,然后根据该响应,您可以使用JavaScript构建html,也可以调用{{3}加载html的方法。