<td>
<input type="button" value="订单详情"
id="but<s:property value="#o.oid"/>"
οnclick="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.创建异步对象
var xhr = 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=
"+new Date().getTime(),true);
// 4.发送
xhr.send(null);
but.value = "关闭";
}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>
// 根据订单的id查询订单项:
public String findOrderItem(){
// 根据订单id查询订单项:
List<OrderItem> list = orderService.findOrderItem(order.getOid());
// 显示到页面:
ActionContext.getContext().getValueStack().set("list", list);
// 页面跳转
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 实现 ajax 异步 兼容浏览器
最新推荐文章于 2022-11-17 09:56:53 发布