Generally, opening a new window in js is very simple, just window.open(url); and that’s it,
But because I want to pass parameters to the server, and the parameters seem to be a long string, and the length of parameters submitted in the get method is limited, so I have the following requirements:
1. Implement post submission in js
2. The returned page will be displayed in a new window
First I did this:
$.ajax({
Type: "POST",
url: '${contextPath}/analyse/detail.do',
data: {carNum:carNum,ids:refIds},
Success: function(str_response) { var obj = window.open("about:blank");
});
Submitted through jQuery ajax, the returned data is written in a new page, but because the browser will intercept the automatic pop-up window, the user needs to unblock it himself, and the user experience is very poor,
Then I implemented it by simulating form submission
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) {
opt.name = x;
opt.value = PARAMS[x];
temp_form .appendChild(opt);
document.body.appendChild(temp);
temp_form .submit();
}
Note: If you want to open a new window, the target attribute of the form must be set to '_blank'
Then request post('${contextPath}/analyse/detail.do',{carNum:carNum,ids:refIds}); and that’s it