在firefox插件中发送POST请求(javascript)

Pin*_*rax 2 javascript post firefox-addon firefox-addon-sdk

使用firefox插件(javascript)我正在尝试向服务器发送POST请求以获取会话ID,但是传统方法似乎都没有用,我已经尝试过xmlhttprequest并且无法使用表单获取它是因为它是内部代码.有没有办法让这个工作,甚至使用插件SDK?

参考我的尝试:

Javascript在firefox插件中通过POST发送数据

Firefox扩展中的javascript中的HTTP POST

tim*_*-we 5

使用新的Addon SDK,您应该使用新的Request API而不是XMLHttpRequest.新的界面也更容易使用.

这是一个简单的例子:

// make sure this gets executed BEFORE making the Request
var Request = require("sdk/request").Request;

Request({
  url: "http://example.com/hello-world.php",
  content: { hello: 'world' },
  onComplete: function (response) {
    console.log( response.text );
  }
}).post();
Run Code Online (Sandbox Code Playgroud)

我建议你看一下这个MDN教程:入门