我有一个包含用户名和密码字段的登录表单,提交表单后,我的应用程序正在重定向到 PHP 响应。在这里,我想获取 JSON 响应以加载到商店中,并且应用程序不应重定向到返回 JSON 数据的 PHP 文件。
问问题
796 次
2 回答
0
//Ext Js
loginForm.submit({
success: function(form, action){
switch(action.result.status)
{
case 'ok' : document.location = 'index.php'; break;
case 'failed':
login_info.setHTML(action.result.msg);
login_info.show();
break;
}
},
failure: function(form, action){
login_info.setHTML('Communication error with the server');
login_info.show();
}
});
//php
if( $condition ){
// login success
$response = array('success'=>true, 'status'=>'ok', 'msg'=>'');
}else{
//failure
$response = array('success'=>true, 'status'=>'failed', 'msg'=>utf8_encode('User or password incorrect'));
}
echo json_encode($response);
于 2013-04-15T18:28:48.527 回答
0
在php中写
echo json_encode($array);
在 ExtJs 中你需要 write 方法来请求你的 php
于 2013-04-12T12:55:03.533 回答