求教同一个页面如何发送多个不同的ajax请求
比如下面这段代码,我假如要再加个ajax请求从而显示<divid="xx2"></div>的话,上面的代码该如何修改呢?<scriptlanguage="javascri...
比如下面这段代码,我假如要再加个ajax请求从而显示<div id="xx2"></div>的话,上面的代码该如何修改呢?
<script language="javascript">
var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request){
alert("对不起,出错了!");
}
function get_inf(){
now_time=new Date().getTime();
var url="test.asp?now_time="+now_time+"&bm="+escape(document.getElementById("mdep").value)+"";
request.open("get", url, true);
request.onreadystatechange = updatePage;
request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
request.send(null);
}
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
document.getElementById("xx").innerHTML=unescape(request.responseText);
}
}}
</script>
<body>
<input name="input1" id="input1" type="text" />
<select name="mdep" id="mdep" onchange="javascript:get_inf()">
<option value=""></option>
<option value="a">a</option>
<option value="b">b</option>
</select>
<div id="xx"></div>
</body>
</html> 展开
<script language="javascript">
var request = false;
try {
request = new XMLHttpRequest();
} catch (trymicrosoft) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (othermicrosoft) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = false;
}
}
}
if (!request){
alert("对不起,出错了!");
}
function get_inf(){
now_time=new Date().getTime();
var url="test.asp?now_time="+now_time+"&bm="+escape(document.getElementById("mdep").value)+"";
request.open("get", url, true);
request.onreadystatechange = updatePage;
request.setRequestHeader('Content-type','application/x-www-form-urlencoded');
request.send(null);
}
function updatePage() {
if (request.readyState == 4) {
if (request.status == 200) {
document.getElementById("xx").innerHTML=unescape(request.responseText);
}
}}
</script>
<body>
<input name="input1" id="input1" type="text" />
<select name="mdep" id="mdep" onchange="javascript:get_inf()">
<option value=""></option>
<option value="a">a</option>
<option value="b">b</option>
</select>
<div id="xx"></div>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询