An alternative to XMLHttpRequest?

Jacques Blom picture Jacques Blom · Feb 29, 2012 · Viewed 15.9k times · Source

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

Answer

SLaks picture SLaks · Feb 29, 2012

You're looking for JSONP.