📄 e0666c3a003d001d1b95a0cb25729fd2
字号:
<%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'shoupiao.jsp' starting page</title>
<script language="javascript">
var Currobj=null;
//var Currobj1=null;
//parentobj上级对象
function changecode(parentobj,obj)
{
if (obj==null) return ;
obj.length = 0;
Currobj=obj;
// Currobj1=sonobj;
var selectcode=parentobj.options[parentobj.selectedIndex].value;
//alert(selectcode);
obj.options[0] = new Option('请选择车厢','');
//sonobj.option[0]=new Option('请选择','');
document.getElementById("datapro").innerHTML = "正在取数据,请稍后......";
send_request("ajax.jsp?code="+selectcode);
}
function changecode1(parentobj,obj,obj2)
{
if (obj==null) return ;
obj.length = 0;
Currobj=obj;
// Currobj1=sonobj;
var selectcode=parentobj.options[parentobj.selectedIndex].value;
var selectcode1=obj2.options[obj2.selectedIndex].value;
obj.options[0] = new Option('请选择座位','');
//sonobj.option[0]=new Option('请选择','');
document.getElementById("datapro").innerHTML = "正在取数据,请稍后......";
var h=send_request("ajax.jsp?code1="+selectcode1);
alert(h);
}
var http_request = false;
//向服务器发起XMLHTTP请求。
function send_request(url)
{//初始化、指定处理函数、发送请求的函数
http_request = false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest)
{ //Mozilla 浏览器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {//设置MiME类别
http_request.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject)
{ // IE浏览器
try
{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {}
}
}
if (!http_request)
{ // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}
http_request.onreadystatechange = processRequest;
// 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("GET", url, true);
http_request.send(null);
}
// 处理返回信息的函数
function processRequest()
{
if (http_request.readyState == 4)
{ // 判断对象状态
if (http_request.status == 200)
{ // 信息已经成功返回,开始处理信息
var returnStr = http_request.responseText;
if(returnStr.indexOf("Error")==-1) //正确
{
var list = returnStr.split('$');
var len =list.length;
var code;
var name;
var p;
var line;
var strlen;
for(var i=0; i<len; i++)
{
line=list[i];
line=line.replace(/(^[\\s]*)|([\\s]*$)/g, "");//删除空格
if (line!="")
{
if(line.length>0)
{
p=line.indexOf(",");
//alert(line+":line");
code=line.substr(0,p);
//alert(p+":p");
strlen=line.length;
//alert(strlen+":strlen");
name=line.substr(p+1,strlen-p);
//alert(name);*/
//Currobj.options[Currobj.length]
//= new Option(line,line);
Currobj.options[Currobj.length]
= new Option(name,name);
}
}
}
document.getElementById("datapro").innerHTML = "取数据完成";
}
else
{
document.getElementById("datapro").innerHTML = "错误";
}
} else
{ //页面不正常
alert("您所请求的页面有异常。");
}
}
}
</script>
</head>
<body>
<form action="shoupiao.jsp" method="post"
enctype="application/x-www-form-urlencoded" name="myform"
target="_self">
车次
<select name="checi" onChange="changecode(checi,chexiang)">
<%
com.ajax.Ajax op=new com.ajax.Ajax();
out.println(op.getMessage());
%>
</select>
车厢
<select name="chexiang" onChange="changecode1(chexiang,zuowei,checi)">
<option selected value="">
您可以预定的车厢
</option>
</select>
座位
<select name="zuowei">
<option selected value="">
您可以预定的座位
</option>
</select>
<label id="datapro">
</label>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -