AjAX基础入门级代码
2006-05-10 15:52
429 查看
<html>
<head>
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="0">
</head>
<body>
<form>
<p>City: <input type="text" name="city" id="city" size="25"
/></p>
<p>State: <input type="text" name="state" id="state" size="25"
/></p>
<p>Zip Code: <input type="text" name="zipCode" id="city" size="5" onclick="changenull()" /></p>
<input type="button" value="¸Ä±ä" onclick="changehave()" />
</form>
<script language="javascript" type="text/javascript">
/* 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();
}
if (!xmlHttp)
alert("Error initializing XMLHttpRequest!");
function getCustomerInfo() {
var phone = document.getElementById("phone").value;
var url = "/cgi-local/lookupCustomer.php?phone=" + escape(phone);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}
function updatePage() {
if (xmlHttp.readyState == 4)
if (xmlHttp.status == 200){
var response = xmlHttp.responseText.split("|");
document.getElementById("order").value = response[0];
document.getElementById("address").innerHTML =
response[1].replace(//n/g, "<br />");
}
else if (request.status == 404)
alert("Request URL does not exist");
else
alert("Error: status code is " + request.status);
}
var city = document.getElementById("city").value;
var state = document.getElementById("state").value;
// Only go on if there are values for both fields
if ((city == null) || (city == ""))
document.getElementById("city").value = "city";
if ((state == null) || (state == ""))
document.getElementById("state").value = "state";
function changenull(){
if (document.getElementById("city").value == "city")
document.getElementById("city").value = "";
}
function changehave(){
if (document.getElementById("city").value == "")
document.getElementById("city").value = "city";
}
</script>
</body>
</html>
<head>
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
<META HTTP-EQUIV="expires" CONTENT="0">
</head>
<body>
<form>
<p>City: <input type="text" name="city" id="city" size="25"
/></p>
<p>State: <input type="text" name="state" id="state" size="25"
/></p>
<p>Zip Code: <input type="text" name="zipCode" id="city" size="5" onclick="changenull()" /></p>
<input type="button" value="¸Ä±ä" onclick="changehave()" />
</form>
<script language="javascript" type="text/javascript">
/* 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();
}
if (!xmlHttp)
alert("Error initializing XMLHttpRequest!");
function getCustomerInfo() {
var phone = document.getElementById("phone").value;
var url = "/cgi-local/lookupCustomer.php?phone=" + escape(phone);
xmlHttp.open("GET", url, true);
xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}
function updatePage() {
if (xmlHttp.readyState == 4)
if (xmlHttp.status == 200){
var response = xmlHttp.responseText.split("|");
document.getElementById("order").value = response[0];
document.getElementById("address").innerHTML =
response[1].replace(//n/g, "<br />");
}
else if (request.status == 404)
alert("Request URL does not exist");
else
alert("Error: status code is " + request.status);
}
var city = document.getElementById("city").value;
var state = document.getElementById("state").value;
// Only go on if there are values for both fields
if ((city == null) || (city == ""))
document.getElementById("city").value = "city";
if ((state == null) || (state == ""))
document.getElementById("state").value = "state";
function changenull(){
if (document.getElementById("city").value == "city")
document.getElementById("city").value = "";
}
function changehave(){
if (document.getElementById("city").value == "")
document.getElementById("city").value = "city";
}
</script>
</body>
</html>
相关文章推荐
- AJAX基础代码
- 在Jeffrey Zhao的基础上+反编译System.Web.Extensions.Design得到的完整Ajax代码
- AJAX基础入门实例教程(含代码)
- ajaxfileupload.js 在别人代码的基础上,自己处理了一些问题,留着备用
- ajax基础代码
- Ajax基础 (十一)---代码测试,资源及框架介绍
- 使用$.getJSON实现跨域ajax请求示例代码
- unity基础开发----页面加载动画代码
- 【web++_第三阶_Ajax_Rest篇】Ajax 第一篇:基础解释和联系,附解释与Rest关系_5
- 笔记-Ajax[2]-代码的实现。
- ajax 基础
- 【android基础开发】省钱达人UI—初级开发练手的好代码
- webpack基础——代码分离
- AJAX实现一个简单的相册和里头包含一些DOM基础应用
- java基础之多线程复制文件代码演示
- Ajax基础知识整理---ajax中异步的概念
- Ajax基础
- Python 3.x 学习:Python 基础代码(二)
- [Web-Harvest数据采集之二]Web-Harvest基础-抓取java代码分析
- Ajax封装代码