XMLHttpRequest POST and open target page in new window/tab

落花浮王杯 提交于 2019-12-09 19:25:18

问题


How do you emulate Form's 'POST' action with target="_blank" in XMLHttpRequest? (ie post data and open target page in a new tab)


回答1:


gBrowser offers this functionality right out of the box.

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});


来源:https://stackoverflow.com/questions/24776180/xmlhttprequest-post-and-open-target-page-in-new-window-tab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!