admin管理员组文章数量:1538414
script中代码
var xmlHttp = false;
function getServer()
{
/@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();
}
}
//点击后显示国内机场 (isdemestic=1:国内,=0:国际)
function ajaxareapot()
{
getServer();
var areaname=document.getElementById(‘areaname’).value;
// alert(areaname);
var url;
url=”queryAreaWithAirpotDrome.action”+
“?areaname=”+encodeURI(areaname)+
“&m=”+Math.random();
xmlHttp.open(“GET”, url, true);
xmlHttp.setRequestHeader( “Content-Type”, “text/html;charset=UTF-8” );
//获取执行状态
xmlHttp.onreadystatechange = function()
{
//如果执行是状态正常,那么就把返回的内容赋值给上面指定的层
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
{
var response = xmlHttp.responseText;
document.getElementById(“airpot”).innerHTML=response;
//alert(response);
}
};
//发送空 Send the request
xmlHttp.send(null);
}
java代码
//ajax
this.getHttpServletResponse().setContentType(“text/xml; charset=UTF-8”);
List locations=null;
PrintWriter pwrite=this.getHttpServletResponse().getWriter();
StringBuffer sb=new StringBuffer();
//用城市ID查询城市机场
if(areatravel!=null && !areatravel.equals("") && areatravel.getId()!=null){
//System.out.println(areatravel.getId());
List list = manager.getAreaPotWithId(String.valueOf(areatravel.getId()));
sb.append("<select name='aircode'>");
for(int i=0;i<list.size();i++){
AirPot air = (AirPot) list.get(i);
sb.append("<option value="+air.getCode()+" ");
sb.append("id="+air.getCode());
sb.append(">");
sb.append(air.getNamecn());
sb.append("</option>");
//System.out.println(((AirPot)list.get(i)).getNamecn());
}
}
sb.append("</select>");
pwrite.write(sb.toString());
pwrite.close();
return null;
版权声明:本文标题:IE浏览器,ajax万能写法。 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dongtai/1726974034a1092593.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论