ajax对象使用的简单实例
来源:互联网 发布:淘宝usa商城 假货 编辑:程序博客网 时间:2024/05/24 03:13
<%@page pageEncoding="utf-8" contentType="text/html;charset=utf-8"%>
<html>
<head>
<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
</head>
<body style="font-size: 30px; font-style: italic;">
<select name="city" id="s1" onchange="getCity(this.value, true)">
<option value="bj">
北京
</option>
<option value="hb">
河北
</option>
<option value="sd">
山东
</option>
</select>
<select name="city1" id="s2">
</select>
</body>
<script type="text/javascript">
$(function() {
getCity('bj', true);
});
var ajaxActionFlag = "0";
function getCity(val, waitingFlag) {
if (ajaxActionFlag == "1" && !waitingFlag) {
alert("数据提交中,请等待");
return;
}
cursor_wait();
var url = "/getCity.do";
var ajax = getXhr();
ajax.open("POST", encodeURI(url), true);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send('city=' + val);
ajaxActionFlag = "1";
ajax.onreadystatechange = function() {
if (ajax.readyState == 1) {
} else {
if (ajax.readyState == 2) {
} else {
if (ajax.readyState == 3) {
} else {
if (ajax.readyState == 4) {
if (ajax.status == 200) {
$('#s2').innerHTML = "";
var txt = ajax.responseText;
var strs = txt.split(';');
for ( var i = 0; i < strs.length; i++) {
var str1s = strs[i].split(',');
var option = new Option(str1s[0], str1s[1]);
document.getElementById('s2').options[i] = option;
}
}
ajaxActionFlag = "0";
cursor_clear();
} else {
alert("提交数据出错,请稍后重试!");
ajaxActionFlag = "0";
cursor_clear();
}
}
}
}
};
}
function getXhr() {
var ajax = false;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest != "undefined") {
ajax = new XMLHttpRequest();
}
return ajax;
}
function cursor_wait() {
document.body.style.cursor = 'wait';
}
function cursor_clear() {
document.body.style.cursor = 'default';
}
</script>
</html>
<html>
<head>
<script src="js/jquery-1.9.1.min.js" type="text/javascript"></script>
</head>
<body style="font-size: 30px; font-style: italic;">
<select name="city" id="s1" onchange="getCity(this.value, true)">
<option value="bj">
北京
</option>
<option value="hb">
河北
</option>
<option value="sd">
山东
</option>
</select>
<select name="city1" id="s2">
</select>
</body>
<script type="text/javascript">
$(function() {
getCity('bj', true);
});
var ajaxActionFlag = "0";
function getCity(val, waitingFlag) {
if (ajaxActionFlag == "1" && !waitingFlag) {
alert("数据提交中,请等待");
return;
}
cursor_wait();
var url = "/getCity.do";
var ajax = getXhr();
ajax.open("POST", encodeURI(url), true);
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajax.send('city=' + val);
ajaxActionFlag = "1";
ajax.onreadystatechange = function() {
if (ajax.readyState == 1) {
} else {
if (ajax.readyState == 2) {
} else {
if (ajax.readyState == 3) {
} else {
if (ajax.readyState == 4) {
if (ajax.status == 200) {
$('#s2').innerHTML = "";
var txt = ajax.responseText;
var strs = txt.split(';');
for ( var i = 0; i < strs.length; i++) {
var str1s = strs[i].split(',');
var option = new Option(str1s[0], str1s[1]);
document.getElementById('s2').options[i] = option;
}
}
ajaxActionFlag = "0";
cursor_clear();
} else {
alert("提交数据出错,请稍后重试!");
ajaxActionFlag = "0";
cursor_clear();
}
}
}
}
};
}
function getXhr() {
var ajax = false;
try {
ajax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
ajax = false;
}
}
if (!ajax && typeof XMLHttpRequest != "undefined") {
ajax = new XMLHttpRequest();
}
return ajax;
}
function cursor_wait() {
document.body.style.cursor = 'wait';
}
function cursor_clear() {
document.body.style.cursor = 'default';
}
</script>
</html>
0 0
- ajax对象使用的简单实例
- ajax的简单实例 XMLHttpRequest对象
- 简单的ajax实例
- 简单的Ajax实例
- 简单的Ajax对象
- ajax的一些简单实例
- 一个简单的ajax实例
- 一个简单的AJAX实例
- 一个简单的ajax实例
- 一个简单的AJAX实例
- AJAX的一个简单实例
- 一个简单的ajax实例
- 最简单的ajax实例
- 一个简单的Ajax实例
- 简单的Ajax应用实例
- Ajax 简单的实例代码
- php的ajax简单实例
- Ajax的简单使用
- Python 爬虫学习:爬取LeetCode的题目并且按照难度分类
- A PAPER LIST FOR OBJECT DETECTION IN VIDEOS
- 线程的分类
- hiho 挑战赛16 B 王胖浩与环
- 阿里云ubuntu14.04 64位 java web环境的搭建
- ajax对象使用的简单实例
- 仿函数
- 在中国爱国企业家联盟我们应微笑应对生活
- ViewPager
- 排列序号
- C++日志类libglog使用
- 二维几何常用模板
- Floyd求最小环 hdu1599 find the mincost route
- Android静态注册广播receiver检测WIFI连接状况变化