Reputation: 165
Hello I'd be super grateful for help with this Firefox API question.
I have a webpage listening for a POST variable called sausage:
<!DOCTYPE HTML>
<body>
<?php
echo $_POST['sausage'];
?>
Using the Request API in the Firefox addon SDK, I've made a button which is supposed to load my webpage while sending the POST variable sausage:
var buttons = require('sdk/ui/button/action');
var tabs = require("sdk/tabs");
var Request = require("sdk/request").Request;
var button = buttons.ActionButton({
id: "mozilla-link",
label: "Visit Mozilla",
icon: {
"16": "./icon-16.png",
"32": "./icon-32.png",
"64": "./icon-64.png"
},
onClick: handleClick
});
function handleClick(state)
{
tabs.open({
url: "http://localhost/home.php/",
onOpen: runScript
});
}
function runScript(tab)
{
Request({
url: "http://localhost/home.php/",
content: { sausage: 'sausage' }
}).post();
}
This is loading the target page, but not sending the POST variable, so the php echo function throws an error. Please can someone explain what's gone wrong. I especially would like to avoid using any of the lower level API functions because this looks like the kind of job Request should eat for breakfast. Thanks in advance!
Upvotes: 1
Views: 1668
Reputation: 5830
The request api doesn't send the variable when opening the tab, it instead makes a second request to the same url. Check your server logs or the browser console, you should see two requests every time you click that button.
Upvotes: 1