1.省市联动2.用户名无刷新验证3.股票信息的实时更新4.天气预报5.qq聊天室

ajax代理

ajax回传的数据格式:字符串,xml,json

注意:eval("("+json+")"); eval存在一定的安全缺陷,一般无伤大雅

json的数据格式:
{ "paramArray":
[{"param1":"str1","param2":"str2","param3":"str3"},{"param1":1,"param2":"str2","param3":"str3"}],
"array":["param1":"str1","param2":"str2","param3":"str3"],"param":"simple"
}
ajax的基本语法--数据传送方式

1.xmlRequest.open("get",url,true)//打开连接,但是并没有发送
  xmlRequest.send(null);    //设为null
2.xmlRequest.setrequsetheader("content-type":"");//必须的
  xmlRequest.open("post",url.true)    //true:表示异步,false:表示同步
  xmlRequest.send(data);    //需要传送的数据

---省市联动
xxx.js

function  creatXmlHttp(){var xmlrequest=null;try  {xmlrequest= new XMLHttpRequest();}catch  {try{xmlrequest=new ActiveXObject("Microsoft.XMLHTTP");}catch  {alert("sorry.your explore don't support this function");}return xmlrequest;
}functon $get(id){return document.getElementById(id);   //.value取节点值
}

xxxpro.php

<?php
header("Content-Type:text/html;charset=utf-8");  //此处与返回格式对应
header("Cache-Control:no-cache");
$cityList=$_POST["cityList"];
for(i=0;i<count(cityList);i++){//暂时不操作数据库if(cityList(i)=="city1")  {echo"{"subcity11":"city1","subcity12":"city2","subcity13":"city3"}";}  else if(cityList(i)=="city2")  {//json $res.='{"cityname":'.$cities[$i].',"price":'.rand(500,1500).'}';echo"{"subcity11":"city4","subcity12":"city5","subcity13":"city6"}";   }
}
?>

xxxview.php

<select id="pro" οnchange="sendRequest();">
<option value=""></option>
<option value="city1">city1</option>
...
<select/>
<select id="city" value="">
...
<select/><script type="text/script" language="javascript">
function sendRequest()
{var xmlRequest=creatXmlHttp();//注意用法var data="city[]=city1&city[]=city2&city[]=city3";var url="xxxpro.php?cityList="+data;xmlRequest.setRequestHeader("Content-Type:");xmlRequest.open("Post",url,true);xmlRequst.onreadystatechange=profun;    //一个是函数的引用,一个是赋函数的地址。profun带不带()的区别xmlRequest.send(data);
}
function profun()
{if(xmlRequest.readystate=4 && xmlRequest.status=200){$get("city").length=0;var subCityList=eval("("+xmlRequest.responseText+")");   //responseXML,返回类型为xml对象(xml dom)var subcitys =xmlRequest.responseXML.getElementsByTagName;var val =mes[0].childNodes[0].nodeValue;for(var i=0;i<subcitys;i++){var city_name=subCityList[i].childNodes[0].subcity11;var subcity=document.createElement("option");//注意语法subcity.value=city_name;subcity.innerText=city_name;$get("city").appendChild(subcity);...}}
}</script>

小知识:
1.<?php
?>   //当此文件为被引用文件时,最好不必带上。
     //当此文件引用其他文件时,最好带上。
2.ie下的get ajax,如果url不发生变化,ie会从缓存中取数据,而不真正的发生请求。----解决方法:为url加上时间戳(new Date()),或者在服务器回送结果时,禁用浏览器缓存
3.边输入边验证  οnkeyup="ajax()"
4.dom 分为 xml dom和html dom
5.smarty->assign($list);   //smarty提供数据展现方式
6.js typeof(var)   //返回变量类型
7.js 中的数组长度length, size(),php中的数组长度count($arr);
8.xml是最通用的数据格式
9.js 定时器 setInterval(函数名,5000);
10.file_put_contents("文件名","写入内容",写入方式);
11.FILE_APPEND          //向指定文件中添加指定信息,此方式为调试程序的神器

数据库知识点:
1.表过大会影响查询速度,解决办法合理分表。
2.数据库群集,定时回传,(手机漫游,qq的通讯方式)

转载于:https://www.cnblogs.com/Watcher/p/3576745.html

php教程笔记复习1-ajax相关推荐

  1. 燕十八ajax笔记,燕十八php視频教程笔记(PHP基础部分).doc

    燕十八php視频教程笔记(PHP基础部分) 001-开学典礼 002-变量概念及命名规范 <?php //?$a?是钥匙[107房间],?房间里的内容是值, /* echo?$a,?什么过程? ...

  2. JavaWeb全套教程笔记_前端技术

    JavaWeb全套教程笔记第一阶段_前端技术 自己整理一套详细的笔记资料,可以满足平时查阅复习,还能帮助别人学习JavaWeb知识.JavaWeb教程分为四个阶段 前端技术 1.HTML.2.CSS. ...

  3. 台湾国立大学郭彦甫Matlab教程笔记(20) root finding(numeric)

    台湾国立大学郭彦甫Matlab教程笔记(20) root finding(numeric) symbolic vs. numeric符号法和数值法的区别对比 symbolic 1)advantages ...

  4. 台湾国立大学郭彦甫Matlab教程笔记(16) 数值微分 numerical differentiation

    台湾国立大学郭彦甫Matlab教程笔记(16) 数值微分 numeric differentiation 复习:diff()函数用来计算vector前后 entry的差异 数值微分继续 various ...

  5. C#(Csharp)基础教程(上)(菜鸟教程笔记)

    博客已更新:C#(Csharp)基础教程(中)(菜鸟教程笔记) 内容包括:判断.循环.封装.方法.可空类型.数组.字符串.结构体.枚举. 目录 1. C# 及其开发环境简介 1.1 C# 概述 1.2 ...

  6. 优秀教程:创建基于 Ajax 的文件拖放上传功能

    分享来自 Tutorialzine 的优秀教程--创建基于 Ajax 的文件拖放上传功能,结合 jQuery File Upload 插件和 jQuery Knob 插件实现漂亮的 CSS3/JS 驱 ...

  7. 台湾国立大学郭彦甫Matlab教程笔记(22) Cramer's method(Inverse matrix逆矩阵法)

    台湾国立大学郭彦甫Matlab教程笔记(22) Cramer's method(Inverse matrix) matrix left division左除:\ or mldivide() solvi ...

  8. 台湾国立大学郭彦甫Matlab教程笔记(21)linear equations(高斯消去法和追赶法)

    台湾国立大学郭彦甫Matlab教程笔记(21) today: linear equation 线性方程 linear system 线性系统 我们先看第一部分 linear equation 假定一个 ...

  9. 台湾国立大学郭彦甫Matlab教程笔记(17)numerical integration

    台湾国立大学郭彦甫Matlab教程笔记(17)numerical integration 数值积分 calculating the numerical value of a definite inte ...

  10. 台湾国立大学郭彦甫Matlab教程笔记(15)polynomial integration 多项式积分

    台湾国立大学郭彦甫Matlab教程笔记(15) Polynomial integration多项式积分 一个多项式和它的积分如下 MATlAB中如何计算积分? polynomial integrati ...

最新文章

  1. 转移操作主机角色至Windows Server 2012 R2
  2. python包pip安装_python包管理之Pip安装及使用
  3. HashSet、TreeSet和LinkedHashSet
  4. crab-源码-模型和算法
  5. 【Android游戏开发之八】游戏中添加音频-详解MediaPlayer与SoundPool的利弊以及各个在游戏中的用途!...
  6. linux /proc 详解
  7. How to create a hyperlink in SQL Server Reporting Services
  8. lua.c:82:10: fatal error: readline/readline.h: 没有那个文件或目录
  9. adminlte3 动态菜单_一本科学菜单,十倍利润增长 | 跟巴奴学餐饮业的精简风:菜单越薄,利润越厚!...
  10. 脱库和删库的实践及解决方案
  11. oracle 给权限语句,oracle权限语句大全
  12. 多轮对话之对话管理(Dialog Management)
  13. matlab中的方波信号图片_【Matlab】Sound
  14. PPT学习整理(六)从入门到放弃。
  15. DNS安全浅议、域名A记录(ANAME),MX记录,CNAME记录
  16. 新手如何搭建一个比较简单的网站?完全不会代码的新手小白搭建自己的网站流程分享!
  17. PinnedSectionListView原理完全透析
  18. 基于uni-app开发的一款视频播放器插件
  19. 2020.1.13 C语言学习 结构体+结构体数组+结构体指针
  20. 加入控制变量后结果悲催了!

热门文章

  1. 如何编写 maptalks plugin
  2. Ubuntu 网速显示,ssh配置
  3. Python之旅:集合
  4. 嵌套for in循环组合cat方式文件中包含空格问题
  5. 浏览器同源策略及其规避方法
  6. WebService学习之三:spring+cxf整合
  7. android 使用android.support.v7 添加ActionBar
  8. URL提交之前对数据编码
  9. tomcat遇到jre\lib\ext\localedata.pack 时出错
  10. End Game----OO最后一次博客作业