JS 实现 ajax 异步浏览器兼容问题
废话不多说了,直接给大家贴代码了,具体代码如下所示:
<td>
<inputtype="button"value="订单详情"
id="but<s:propertyvalue="#o.oid"/>"
onclick="showDetail(<s:propertyvalue="#o.oid"/>)"/>
<divid="div<s:propertyvalue="#o.oid"/>"></div>
</td>
<scripttype="text/javascript">
functionshowDetail(oid){
varbut=document.getElementById("but"+oid);
vardiv1=document.getElementById("div"+oid);
if(but.value=="订单详情"){
//1.创建异步对象
varxhr=createXmlHttp();
//2.设置监听
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(xhr.status==200){
div1.innerHTML=xhr.responseText;
}}
}
//3.打开连接
xhr.open("GET",
"${pageContext.request.contextPath}/
adminOrder_findOrderItem.action?oid="+oid+"&time=
"+newDate().getTime(),true);
//4.发送
xhr.send(null);
but.value="关闭";
}else{
div1.innerHTML="";
but.value="订单详情";
}
}
functioncreateXmlHttp(){
varxmlHttp;
try{//Firefox,Opera8.0+,Safari
xmlHttp=newXMLHttpRequest();
}
catch(e){
try{//InternetExplorer
xmlHttp=newActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
try{
xmlHttp=newActiveXObject("Microsoft.XMLHTTP");
}
catch(e){}
}
}
returnxmlHttp;
}
</script>
//根据订单的id查询订单项:
publicStringfindOrderItem(){
//根据订单id查询订单项:
List<OrderItem>list=orderService.findOrderItem(order.getOid());
//显示到页面:
ActionContext.getContext().getValueStack().set("list",list);
//页面跳转
return"findOrderItem";
}
<tablewidth="100%">
<s:iteratorvar="orderItem"value="list">
<tr>
<td><imgwidth="40"height="45"src="${pageContext.request.contextPath}/<s:propertyvalue="#orderItem.product.image"/>"></td>
<td><s:propertyvalue="#orderItem.product.pname"/></td>
<td><s:propertyvalue="#orderItem.count"/></td>
<td><s:propertyvalue="#orderItem.subtotal"/></td>
</tr>
</s:iterator>
</table>
以上所述是小编给大家介绍的JS实现ajax异步浏览器兼容问题,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!