Greasemonkey: “GM_xmlhttpRequest is not defined” with the new update

心已入冬 提交于 2019-12-08 08:15:08

问题


Why this simple Greasemonkey script is not working for me https://jsfiddle.net/pghnsw8z/1/ ? I mean that instead of getting successful response I get error while making an ajax call.

// ==UserScript==
// @name        _Starter AJAX request in GM, TM, etc.
// @match       *://php.net/*
// @grant       GM_xmlhttpRequest
// @connect     php.net
// ==/UserScript==

GM_xmlhttpRequest ( {
    method:     'GET',
    url:        'http://php.net/',
    onload:     function (responseDetails) {
                    // DO ALL RESPONSE PROCESSING HERE...
                                alert(responseDetails);
                    console.log (
                        "GM_xmlhttpRequest() response is:\n",
                        responseDetails.responseText.substring (0, 80) + '...'
                    );
                }
} );

I found the script here https://stackoverflow.com/a/42592356/9483949 and it seems it worked well for someone earlier.

I'm using Firefox 59.0.1 and Greasemonkey 4.3

Restarting Firefox and reinstalling script didn't help.


回答1:


The doc : https://wiki.greasespot.net/GM.xmlHttpRequest

The GM API was changed. You have to use xmlHttpRequest property of GM class, it is compatibility: GM 4.0+.

Replace GM_xmlhttpRequest by : GM.xmlHttpRequest like this :

// ==UserScript==
// ...
// @grant         GM.xmlHttpRequest
// ==/UserScript==

GM.xmlHttpRequest({


来源:https://stackoverflow.com/questions/49365651/greasemonkey-gm-xmlhttprequest-is-not-defined-with-the-new-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!