ajax判断
function isAjax() {
if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
if ('xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])) {
return true;
}
}
return false;
}
ajax返回
function ajax_return($data, $info, $status, $type = 'json') {
$result = array();
$result['status'] = $status;
$result['info'] = $info;
$result['data'] = $data;
echo json_encode($result);
exit;
}
转向
function _return($info, $url = '') {
//页面跳转
header("Content-Type: text/html; charset=utf-8");
if (empty($url)) {
$url = @$_SERVER["HTTP_REFERER"];
}
header("refresh:{$time};url={$url}");
//header("Location:$url");
exit($info);
}
跳转
function redirect($url, $time = 0, $msg = '') { //多行URL地址支持 $url = str_replace(array("\n", "\r"), '', $url); if (empty($msg)) $msg = "系统将在{$time}秒之后自动跳转到{$url}!"; if (!headers_sent()) { // redirect if (0 === $time) { header("Location: " . $url); } else { header("refresh:{$time};url={$url}"); //fixed 添加编码 by lee 2011年10月12日 09:29:50 header("Content-type: text/html; charset=utf-8"); echo($msg); } exit(); } else { $str = "'; if ($time != 0) $str .= $msg; exit($str); } }