select下拉框的使用及使用ajax方法取消订单的代码片段
js代码
//根据订单状态查询
function selectedStatus(){
//当前选择的订单状态
var status=$('#orderStatus').val() ;
//用${orderBusType}传参 改变地址栏参数时js报未定义.......
url="${pageContext.request.contextPath}/orderItem/queryProduceItem.do?orderStatus="+status+"&orderBusType="+<%=request.getAttribute("orderBusType")%>;
document.location=url; //此处使用页面刷新
// }
}
jsp中的代码
<select name="select" id="orderStatus" onchange="selectedStatus(this.value);">
<option selected value=""
<c:if test="${orderStatus=='' }"> selected </c:if>>全部状态
</option>
<option value="0"
<c:if test="${orderStatus=='0' }"> selected </c:if>>等待付款</option>
</select>
取消订单
取消订单的jsp代码,在js函数中传入订单的id
<c:if test="${order.orderState ne '2' && order.orderState ne '6' && order.orderBiaoShi ne '3'}">
<a onclick="cancelOrder('${order.orderId }');" class="redDA0004">取消订单</a>
</c:if>
//ajax方式取消订单
function cancelOrder(orderid){
if(confirm("确认要取消该订单吗")){
$.ajax({
type:'POST',
url:'${pageContext.request.contextPath}/orderItem/cancelOrder.do',
data:'orderid='+orderid,
dataType:'text',
error:function(){
alert("JQuery AJAX Error!");
},
success:function(msg){
alert(msg);
if(msg=='订单取消成功'){
document.location="${pageContext.request.contextPath}/orderItem/queryProduceItem.do?orderBusType="+${orderBusType};
//取消成功之后,地址栏刷新,访问订单列表
}
}
});
}
}
public ActionForward cancelOrder(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
log.info("取消订单开始 cancelOrder start...............");
String orderid = request.getParameter("orderid");
com.sinovatech.shopservice.order.service.manager.ResultInfo oinfo = orderFacade
.getOrderById(orderid);
//响应ajax请求
response.setCharacterEncoding("UTF-8");
TOrderDTO orderDTO = (TOrderDTO) oinfo.getResult();
if (orderDTO == null) {
log.info("取消订单失败,查询当前取消订单为空记录 cancelOrderisFail,orderDTO==null");
response.getWriter().write("取消订单失败");
return null;
}
orderDTO.setOarderId(orderid);
orderDTO.setOrderBiaoshi(3d);// 订单标识(1:是正常订单,2:异常订单,3:撤销订单)
try {
//调用接口 ,更新订单信息,返回结果中保存着操作是否成功
com.sinovatech.shopservice.order.service.manager.ResultInfo rinfo = orderFacade
.updateOrder(orderDTO);
if (rinfo.getResultCode().equals("00100")) {
log.info("取消订单失败 cancelOrderisFail" + rinfo.getErrorDesc());
response.getWriter().write("取消订单失败");
return null;
}
log.info("取消订单成功 cancelOrderisSUCCESS");
response.getWriter().write("订单取消成功");
} catch (Exception e) {
log.info("取消订单失败 cancelOrderisFail" + e.getMessage());
response.setCharacterEncoding("UTF-8");
response.getWriter().write("取消订单失败");
e.printStackTrace();
}
log.info("取消订单结束 cancelOrder end...............");
return null;
}