在ajax中打开新窗口
第一种方式、
$.ajax({ type : 'POST',url : '<%=basePath%>cms/payment.action',data : {refundNo:refundNo,orderNo:orderNo},dataType:'json',async:false }).done(function(o){ var data=o.data; if(data=="notrade"){ $.messager.alert('提示','没有该交易记录,您不能进行打款操作','info'); }else if(data=="build error"){ window.open("http://www.baidu.com"); } }).fail();
第二种方式
function haha(){ $.ajax({ type : 'POST',orderNo:orderNo,refundFee:refundFee},async:false,success:function(o){ var data=o.data; if(data=="notrade"){ $.messager.alert('提示','info'); }else if(data=="alipay"){ var keys=new Array("orderNo","refundNo","refundFee"); var values=new Array(orderNo,refundNo,refundFee); <%--打开新窗口--%> openWindowWithPost("<%=basePath%>cms/alipayRefund.action",keys,values); }else if(data=="handle"){ alert("打款操作正在进行中,请刷新当前页面进行确认打款结果"); } } }) }
//以下是固定的,不需要变动
function openWindowWithPost(url,values) { var newWindow = window.open(url); if (!newWindow) return false; var html = ""; html += "<html><head></head><body><form id='formid' method='post' action='" + url + "'>"; if (keys && values && (keys.length == values.length)) for (var i = 0; i < keys.length; i++) html += "<input type='hidden' name='" + keys[i] + "' value='" + values[i] + "'/>"; html += "</form><script type='text/javascript'>document.getElementById(\"formid\").submit()"+'</script'+'>'+"</body></html>"; newWindow.document.write(html); return newWindow; }原文链接:https://www.f2er.com/ajax/165137.html