An alternative to XMLHttpRequest?
17,973
Solution 1
You're looking for JSONP.
Solution 2
You can use Fetch API its not supported by Safari or IE for now but its a good alternative.
You ma use it as:
function getData(){
fetch('flowers.jpg').then(function(response) {
return response.blob();
})
}
if(self.fetch) {
// run my fetch request here
var resp = getData();
} else {
// do something with XMLHttpRequest?
}
You can get more info from MDN Using Fetch API. You may want More advance usage.
Update: you might find this article useful That's so fetch!
Author by
Jacques Blom
Updated on July 31, 2022Comments
-
Jacques Blom almost 2 years
I am writing a Firefox extension. I am using a content script that matches a specific domain. I want to get data from a PHP page. Eventually adding a CSS file to the page to change the styling. The content of the PHP page will be the name of the CSS file I fetch. Here is my content script javascript, the alert returns nothing.
I was told I am limited by the same origin policy. Is there any way I can get data from the php page?
function getData() { client = new XMLHttpRequest(); try{ client.open('GET','http://localhost:8888/istyla/login/popuplogin/myaccount.php'); } catch (e){ alert( "error while opening " + e.message ); } client.onreadystatechange = function(){ if (client.readyState ==4){ user_data = client.responseText; var currenttheme = user_data; alert (currenttheme); } } client.send(null); } getData();