In js, it is usually very simple to open a new window.open(url); just go.
But since I want to pass parameters to the server, and the parameters look like a long string, and the length of the commit parameters in the get method is limited, I have the following requirements:
1. Implement post submission in js
2. The returned page is displayed in a new window
First of all, I did this:
The code copy is as follows:
$.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);
}
});
Submitted via jQuery ajax, the returned data is written in a new page, but because the browser will intercept the automatically pop-up window, the user still needs to unintercept it himself, and the user experience is very poor.
Then I realized by mocking the form submission
The code copy is as follows:
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();
}
Note: If you want to set the target property of the newly opened window form to '_blank'
Then request post('${contextPath}/analyse/detail.do',{carNum :carNum,ids:refIds});