I’m trying to perform an Ajax query from within a Greasemonkey script, but I’m stuck with not being able to load data from a remote URL. The script only seems to function if the page being viewed is the same domain as the Ajax call. Example:
// ==UserScript== // @name Hello jQuery // @namespace http://www.example.com/ // @description jQuery test script // @include * // @require http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js // ==/UserScript== $(document).ready(function() { $.get('http://www.google.com', function(data){ alert('Data Loaded: ' + data); }); }); // EOF
This user script works perfectly when visiting google.com, but it fails with no error or alert on any other domain. What is the solution?
Only
GM_xmlhttpRequestcan do cross-site access, not the normal XMLHttpRequest that jQuery uses.