【发布时间】:2014-07-16 08:45:11
【问题描述】:
如何在XMLHttpRequest 中使用target="_blank" 模拟Form 的'POST' 操作? (即发布数据并在新标签中打开目标页面)
【问题讨论】:
标签: javascript firefox-addon firefox-addon-restartless
如何在XMLHttpRequest 中使用target="_blank" 模拟Form 的'POST' 操作? (即发布数据并在新标签中打开目标页面)
【问题讨论】:
标签: javascript firefox-addon firefox-addon-restartless
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});
【讨论】:
dataStream.data,我怎样才能传递一个本地文件,即'file:///C:/.../root.png'?
values 被正确编码的意思是:dataStream.data = encodeURIComponent("foo") + "=" + encodeURIComponent("ba-%r") + "&" + encodeURIComponent("@find") + "=" + encodeURIComponent("ba+$@r"); 对吗?
loadOneTab。