我在控制器中设置了这个动作
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();
});
在这个例子中,我设置状态变量(在控制器中)的方式我知道它实际上不起作用。我读了这个链接,在那里我明白有预定义的状态值;success、notmodified、error、timeout或parsererror。
我想知道是否有办法手动设置状态变量,或者我是否可以以其他方式返回变量。
您可以从服务器发送的任何response
字段中获得status
。你为什么要这么做?我认为不可能。
您可以使用$.post()方法将数据发送到服务器并获得状态响应,然后基于该响应,您可以在JavaScript中构建html,或者您可以调用.load()方法来加载html