JS use post to open a new window _javascript tips

Source: Internet
Author: User

JS in general new open window is very simple direct window.open (URL); it's OK,

But since I want to pass parameters to the server, and the parameters look a long string, and the length of the commit parameters of Get mode is limited, I have the following requirements:

Implement post submission in 1,js

2, the returned page is displayed in a new window

First of all, I did it:

Copy Code code 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);
}
});

Through jquery Ajax submission, the returned data is written in the new page, but because the browser will block the pop-up window, so that users need to lift their own interception, the user experience is very poor,

And then I did it by simulating the submission of form forms.

Copy Code code 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 the target property of the newly opened window form to be set to ' _blank '

The

Then requests the post (' ${contextpath}/analyse/detail.do ', {carnum:carnum,ids:refids}); it's OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.