前端之家收集整理的这篇文章主要介绍了
ajax 返回值方法(php),
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
<?PHP
function msg_error($state,$msg) {
if(!empty($_REQUEST['callback'])) {
$callback = $_REQUEST['callback'];
$callback = preg_replace(array('/</','/>/','/"/','/\'/','/\+/','/\\\\/','/\//'),array('<','>','',''),$callback);
}
$a = array(
'state' => $state,'msg' => $msg,);
$ret = json_encode($a);
if(!empty($callback)) $ret = sprintf("%s(%s)",$callback,$ret);
header("Content-type: application/json");
echo $ret;
exit;
}
原文链接:https://www.f2er.com/ajax/161711.html