如何在XMLHttpRequest
中与target="_blank"
模拟表单的'POST'
动作?(即发布数据并在新选项卡中打开目标页面)
gBrowser
提供了这个功能。
var dataStream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(Ci.nsIStringInputStream);
dataStream.data = "foo=bar&alpha=beta"; // make sure the values are properly encoded with encodeURIComponent
var postStream = Cc["@mozilla.org/network/mime-input-stream;1"].createInstance(Ci.nsIMIMEInputStream);
postStream.addHeader("Content-Type", "application/x-www-form-urlencoded");
postStream.addContentLength = true;
postStream.setData(dataStream);
gBrowser.loadOneTab("http://www.example.com/", {inBackground: false, postData: postStream});