So, I’m fairly new to web development, and I’m having a little trouble with something. I want to be able to send a POST request (or really, whatever method allows me to do this), from a Firefox extension/Bookmarklet to a PHP page I control.
I’ve been reading up on cross-origin resource sharing but I haven’t managed to get it to work yet, and I could use a little guidance.
It seems like a jQuery ajax request can make this possible, but I haven’t been able to get this to work yet, perhaps because I’m new to this.
I’ve been reading up on this lately and I’ve been have trouble melding it all together in my head, because it seems like there are a lot of right answers.
Edit:
So the PHP page I’ve got is set up like this:
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: POST");
addLink($_POST['username'], $_POST['password'], $_POST['URL']);
And that function just adds the URL to a database based on the username/password. That’s not an issue.
And I’ve gotten this to work with a request from the same domain:
$(document).ready(function() {
$("a").click(function() {
$.post("sendLinkInfo.php", { username: "<username here>",
password: "<password here>", URL: window.location.href },
});
});
The trouble is doing it cross-domain from an arbitrary bookmarklet/Firefox extension.
Take a look at the jQuery docs:
This should work cross-domain.