欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JS 實(shí)現(xiàn) ajax 異步瀏覽器兼容問題

 更新時(shí)間:2017年01月21日 09:36:05   作者:mine_song  
本文通過實(shí)例代碼給大家講解了js實(shí)現(xiàn)ajax異步瀏覽器兼容問題,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下吧

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:

<td> 
<input type="button" value="訂單詳情" 
id="but<s:property value="#o.oid"/>" 
onclick="showDetail(<s:property value="#o.oid"/>)"/> 
<div id="div<s:property value="#o.oid"/>"></div> 
 </td> 
<script type="text/javascript"> 
function showDetail(oid){ 
var but = document.getElementById("but"+oid); 
var div1 = document.getElementById("div"+oid); 
if(but.value == "訂單詳情"){ 
// 1.創(chuàng)建異步對(duì)象 
var xhr = createXmlHttp(); 
// 2.設(shè)置監(jiān)聽 
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= 
"+new Date().getTime(),true); 
// 4.發(fā)送 
xhr.send(null); 
but.value = "關(guān)閉"; 
}else{ 
div1.innerHTML = ""; 
but.value="訂單詳情"; 
} 
} 
function createXmlHttp(){ 
var xmlHttp; 
try{ // Firefox, Opera 8.0+, Safari 
xmlHttp=new XMLHttpRequest(); 
 } 
catch (e){ 
try{// Internet Explorer 
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
 } 
catch (e){ 
try{ 
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
} 
catch (e){} 
 } 
 } 
return xmlHttp; 
} 
</script> 
// 根據(jù)訂單的id查詢訂單項(xiàng): 
public String findOrderItem(){ 
// 根據(jù)訂單id查詢訂單項(xiàng): 
List<OrderItem> list = orderService.findOrderItem(order.getOid()); 
  // 顯示到頁面: 
ActionContext.getContext().getValueStack().set("list", list); 
  // 頁面跳轉(zhuǎn) 
return "findOrderItem"; 
}  
<table width="100%"> 
 <s:iterator var="orderItem" value="list"> 
 <tr> 
  <td><img width="40" height="45" src="${ pageContext.request.contextPath }/<s:property value="#orderItem.product.image"/>"></td> 
  <td><s:property value="#orderItem.product.pname"/></td> 
  <td><s:property value="#orderItem.count"/></td> 
  <td><s:property value="#orderItem.subtotal"/></td> 
 </tr> 
 </s:iterator> 
</table>

以上所述是小編給大家介紹的JS 實(shí)現(xiàn) ajax 異步瀏覽器兼容問題,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論