PHP中跳转,转向,ajax判断
2013-06-03 20:34
204 查看
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 = "<meta http-equiv='Refresh' content='{$time};URL={$url}>";
$str .='<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
if ($time != 0)
$str .= $msg;
exit($str);
}
}
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 = "<meta http-equiv='Refresh' content='{$time};URL={$url}>";
$str .='<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
if ($time != 0)
$str .= $msg;
exit($str);
}
}
相关文章推荐
- 根据user-agent判断蜘蛛代码黑帽跳转代码(js版与php版本)
- php: 用header()函数解决跳转,ajax跨域,utf8实例
- php判断请求是否是ajax
- PHP中根据IP地址判断城市实现城市切换或跳转代码
- php判断是否为ajax请求摘自thinkphp
- php判断数据是ajax提交还是普通表单提交
- php判断是否为ajax请求的方法
- PHP+Ajax点击加载更多内容 -效果好,速度快,带图片加载和跳转链接 加载最后一页更多变成文字变没记录
- 如何实现网站根据ip判断地区 自动跳转到所属地区页面【PHP版】
- 在php中判断一个请求是ajax请求还是普通请求的方法
- PHP Action中跳转到别的方法、页面中点击链接跳转到ACtion中方法、AJAX提交传参给ACTION
- PHP判断一个请求是AJAX请求还是普通请求
- ajax上传图片类型,ajax上传文件,判断上传图片类型,php上传图片
- php使用ajax实现注册账号时判断账号是否已经存在
- 表单ajax提交不跳转,清空input框值以及php跨域请求数据总结
- PHP代码根据IP判断城市并跳转
- PHP 判断是否为 AJAX 请求
- 利用PHP代码实现网页自动判断转向
- php判断浏览器和系统语言通过搜索引擎随机跳转网站-挂黑链
- 提交表单用ajax判断登录正确并跳转页面的方法