但是由于我希望传递参数到服务端,而且参数看起来很长一串,而且get方式的提交参数长度是有限制的,因此我有以下需求:
1,js中实现post提交
2,返回的页面在新窗口显示
首先我是这么做的:
复制代码 代码如下:
$.ajax({
type: post,
url: '${contextpath}/analyse/detail.do',
data: {carnum :carnum,ids:refids},
success: function(str_response) { var obj = window.open(about:blank);
obj.document.write(str_response);
}
});
通过jquery ajax提交,返回的数据写在新的页面中,但是由于浏览器的会拦截自动弹出的窗口,这样还需用户自己解除拦截,用户体验很差,
然后我又通过模拟form表单的提交来实现
复制代码 代码如下:
function post(url, params) { var temp_form = document.createelement(form);
temp_form .action = url;
temp_form .target = _blank;
temp_form .method = post;
temp_form .style.display = none; for (var x in params) { var opt = document.createelement(textarea);
opt.name = x;
opt.value = params[x];
temp_form .appendchild(opt);
}
document.body.appendchild(temp);
temp_form .submit();
}
注意:如需新打开窗口 form 的target属性要设置为'_blank'
然后请求post('${contextpath}/analyse/detail.do',{carnum :carnum,ids:refids});就可以了
