GM_xmlhttpRequest responseText empty in Firefox but perfect in Chrome

1k views Asked by At

I'm trying to do a userscript for Chrome and Greasemonkey in Firefox.

I'm using the GM_xmlhttpRequest since it supposed to work in both platforms. The request code seems to work in both browsers, but in Firefox the responseText is empty in contrast to Chrome where I get the expected response.

The userscriptcode:

// ==UserScript==  
// @include        *.website.org/Forum/Read.aspx?*  
// ==/UserScript==

        getstr = "thread="+thread+"&day="+getday;
    GM_xmlhttpRequest({
        method: "POST",
        url: "http://www.other.org/js/gm/get.php",
        data: getstr,
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
            "Content-type":"charset=utf-8"
        },
        onload: function(response) {
                        alert(response.responseText);
        }
    });

The php-script on the "other.org" site:

    $json = json_encode($array);
    echo $json;

The userscript handles the response with a JSON.parse(), but that is not important here.

In chrome, this works perfectly, but the responseText is empty in firefox.

I have read about that this might be something to do with the same-origin policies. But I don't understand how this might be and how I can fix it. All help is very welcome!

1

There are 1 answers

0
katspaugh On BEST ANSWER

Objects can't have multiple properties with identical names. Put the charset header value into the first Content-Type.

Also, try adding more headers, Content-Length, specifically. The safest bet is to inspect what headers Firefox sends on normal POST-requests (when you submit the form manually) and copy them all.