Ajax:一种网页开发技术(Asynchronous Javascript + XML)
2024-10-11 05:19:06
- 创建新的 XMLHttpRequest 对象(Ajax 应用程序的核心):
<script language="javascript" type="text/javascript">
var xmlHttp = new XMLHttpRequest();
</script> - 用 JavaScript 代码捕获和设置字段值
//获取 id 值为 first_name 的表单域
var name = document.getElementById('first_name').value; //修改 id 值为 test 的表单域的值
document.getElementById('test').value = response[0]; - 在 Microsoft 浏览器上创建 XMLHttpRequest 对象
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
} - 以支持多种浏览器的方式创建 XMLHttpRequest 对象
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
@end @*/ if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
} - 开始工作:发送Ajax请求
function callServer() {
// Get the city and state from the web form
var city = document.getElementById("city").value;
var state = document.getElementById("state").value; // Build the URL to connect to
var url = "/scripts/getZipCode.php?city=" + escape(city) + "&state=" + escape(state); // Open a connection to the server
xmlHttp.open("GET", url, true); // Setup a function for the server to run when it's done
xmlHttp.onreadystatechange = updatePage; // Send the request
xmlHttp.send(null);
}
最新文章
- hdu 1398 Square Coins (母函数)
- 说说设计模式~桥梁模式(Bridge)
- Linux Shell系列教程之(十六) Shell输入输出重定向
- label WordWrap
- javascript第十一课,string对象
- Access之C#连接Access
- windows下npm scripts不能执行的问题
- Effective Java 之 --- 用私有构造器或者枚举类型强化Singleton属性
- 不安装oracle客户端连接oracle数据库
- SSH通过SSH代理连接到内网机器
- 小程序通过 url 向内嵌 H5 传参注意事项
- css 效果之转换
- vs远程调试 转http://www.cnblogs.com/magicchaiy/archive/2013/05/28/3088274.html
- 算法之LOWB三人组之选择排序
- iOS 字典转json字符串
- sendfile Linux函数
- Java IO流中的flush()
- ZOJ - 3216:Compositions (DP&;矩阵乘法&;快速幂)
- spark 都用了哪些开源东东
- Servlet类源码说明