本文介绍了XMLHttpRequest POST并在新窗口/选项卡中打开目标页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

如何在 target =_ blank来模拟Form的'POST' >的XMLHttpRequest ? (即发布数据,并在新标签中打开目标页面)

解决方案

gBrowser
$ b

  var dataStream = Cc [@ mozilla .ORG / IO /串输入流; 1\" ]的createInstance(Ci.nsIStringInputStream); 
dataStream.data =foo = bar& alpha = beta; //确保值正确编码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});


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

解决方案

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

这篇关于XMLHttpRequest POST并在新窗口/选项卡中打开目标页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 20:07