人人商城前端foxui提示[object,object]
人人商城在做debug时,发现前端弹窗提示[object,object]。
后端输出提示的代码格式
show_json(0, "错误提示内容");
前端输出格式
FoxUI.toast.show(ret.result);
这样会弹窗错误提示[object,object],我们只需要将上述输出格式稍作修改即可。
通过show_json()函数来分析,如果show_json()第2个参数非数组,会自动将result参数写到数组里,正确的输出格式修改如下:
FoxUI.toast.show(ret.result.message);
show_json()函数位置
ewei_shopv2/core/inc/functions.php
show_json()函数内容
if (!(function_exists('show_json')))
{
function show_json($status = 1, $return = NULL)
{
$ret = array('status' => $status, 'result' => ($status == 1 ? array('url' => referer()) : array()));
if (!(is_array($return)))
{
if ($return)
{
$ret['result']['message'] = $return;
}
exit(json_encode($ret));
}
else
{
$ret['result'] = $return;
}
if (isset($return['url']))
{
$ret['result']['url'] = $return['url'];
}
else if ($status == 1)
{
$ret['result']['url'] = referer();
}
exit(json_encode($ret));
}
}