![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
AJAX
文章平均质量分 76
java_zhaoyanli
不忘初衷,善始善终。
展开
-
使用AJAX技术实现“动态页面静态化”
php:<?php//向客户端返回所有的商品类别,以JSON字符串格式header('Content-Type: application/json');$db = [ ['tno'=>101, 'tname'=>'电脑'], ['tno'=>102, 'tname'=>'数码相机'], ['tno'=>103, 'tname'=>'手机'], ['tno'=>104, 'tnam原创 2016-04-11 23:05:28 · 3091 阅读 · 0 评论 -
模拟内容还未加载出来的动态小图画
PHP:<?php//jQuery中的load()方法只能接受服务器返回的HTML响应数据header('Content-Type: text/html');//模拟网速较慢的情形sleep(5);?> 首页 新闻 动态 产品大全HTML: new document 这里是首页中的主体内容 阿里的设计费原创 2016-04-11 23:07:25 · 317 阅读 · 0 评论 -
jQuery对AJAX的封装——$.get(验证用户名是否存在)
php:<?php//判断客户端传递过来的用户名在数据库中是否已经存在,返回'exists'或'non-exists'header('Content-Type: text/plain');$db = ['tom', 'mary', 'king'];$uname = $_REQUEST['uname'];if( in_array($uname, $db) ){ echo 'exi原创 2016-04-11 23:09:20 · 503 阅读 · 0 评论 -
jQuery对AJAX操作的封装——$.post
php:<?php//接收客户端提交的uname/upwd,保存入数据库,//返回一条成功的提示消息$uname = $_REQUEST['uname'];$upwd = $_REQUEST['upwd'];//假装保存入数据库//echo 'SUCCESS!';echo $uname;echo $upwd;?>html: new document原创 2016-04-11 23:10:44 · 1757 阅读 · 0 评论 -
根据客户端浏览器首选语言的不同,返回不同的欢迎消息
php:<?php//header('Content-Type: application/javascript');//根据客户端浏览器首选语言的不同,返回不同的欢迎消息$arr = getallheaders();$lang = $arr['Accept-Language'];if( substr($lang, 0, 2)==='zh' ){ echo 'alert("你好原创 2016-04-11 23:12:08 · 1431 阅读 · 0 评论 -
jQuery对AJAX的封装——$.getJSON
如果php页面写请求头了,那么get和getjson是一样的。<?phpheader('Content-Type: application/json');//一次向客户端返回三个员工信息,以JSON格式$output = [];for($i=0; $i<3; $i++){ $eno = rand(1000,10000); $ename = 'Tom'.rand(1000, 100原创 2016-04-11 23:14:57 · 377 阅读 · 0 评论 -
异步请求一个不存在的页面
php:<?phpheader('HTTP/1.1 500 Server Interval Error');?>html: new document 异步请求一个不存在的页面 $('#bt1').click(function(){ /*$.get('7-1.php', function(){ console.log(原创 2016-04-11 23:25:36 · 524 阅读 · 0 评论