解决ajax跳转页面HTTP Status 400 - Required Long parameter 'xx' is not present问题

应用情况,ajax传值已经到controller 方法也正确,就是不跳转页面的情况。(这是我在工作中碰到的,当时确信我的后台没有问题,就去问前端

实例代码:function print(){
/* var odid = $(obj).find("#odid").val(); */
var list =[]; 
$('input[name="test"]:checked').each(function(){ 
list.push($(this).val()); 
}); 

alert(list.length==0 ?'你还没有选择任何内容!':list); 
$.ajax({
url : "/manger/order/ticketorderPrint.do?",
data : {
"list" : list
},
dataType : "html",!!!!!之前写的是json。
success : function(data) {
console.log(data);
if (data!=null) {
var newwin=window.open('','','');!!!加上这一步后完美解决!
  newwin.opener = null;
  newwin.document.write(data);
//window.open('/manger/order/ticketorderPrint.do?datas='+list);
}
},
async : false,
/* 测试时候用的 error:function(XMLHttpRequest, textStatus, errorThrown) {   
                    alert(XMLHttpRequest.status);  
                       alert(XMLHttpRequest.readyState);  
                       alert(textStatus);  
                alert('读取超时,请检查网络连接'); 
} */
}); 
 
 
}
解决方案:把dataType写成htmtl。再贴上一段代码: if (data!=null) {
var newwin=window.open('','','');!!!加上这一步后完美解决!
  newwin.opener = null;
  newwin.document.write(data);
//window.open('/manger/order/ticketorderPrint.do?datas='+list);
}
},
把你的从后台返回的数据直接写到那个页面!

猜你喜欢

转载自blog.csdn.net/weixin_42338186/article/details/80499117