Greasemonkey AJAX request from a different domain? Greasemonkey AJAX request from a different domain? ajax ajax

Greasemonkey AJAX request from a different domain?


Greasemonkey (and Tampermonkey) has built-in support for cross-domain AJAX. Use the GM_xmlhttpRequest function.

Here's a complete userscript that illustrates the process:

// ==UserScript==// @name        _Starter AJAX request in GM, TM, etc.// @match       *://YOUR_SERVER.COM/YOUR_PATH/*// @grant       GM_xmlhttpRequest// @connect     targetdomain1.com// ==/UserScript==GM_xmlhttpRequest ( {    method:     'GET',    url:        'http://targetdomain1.com/some_page.htm',    onload:     function (responseDetails) {                    // DO ALL RESPONSE PROCESSING HERE...                    console.log (                        "GM_xmlhttpRequest() response is:\n",                        responseDetails.responseText.substring (0, 80) + '...'                    );                }} );

You should also get in the habit of using the @connect directive -- even though it's not strictly required for Greasemonkey on Firefox, yet.