Side navigation
#5165 closed bug (invalid)
Opened September 04, 2009 10:51AM UTC
Closed October 19, 2010 11:47PM UTC
jasonp doesn't work in greasemonkey user script, when loading jQuery via @require
Reported by: | pilat | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | 1.4 |
Component: | ajax | Version: | 1.3.2 |
Keywords: | greasemonkey, require, ajax, jsonp | Cc: | |
Blocked by: | Blocking: |
Description
After reading about new "@require" feature (in Greasemonkey 0.8), I've tried to rewrite my user script, that uses JQuery, accordingly.
I used the following code earlier:
...
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'URL_to_jquery-1.3.2.min.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
Check if jQuery's loaded
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();
All your GM code must be inside this function
function letsJQuery() {
...
}
-----------
And I've tried to replace is by:
-----------
...
// @require URL_to_jquery-1.3.1.min.js
...
$(document).ready(function() {
...
});
-----------
After this, I've got most of JQuery functions working in my userJS script, as expected. However, cross-site requests stopped working.
Here's the code I'm using:
$.ajax({
type: "GET",
url: "URL_TO_my_own_script.php",
data: {
action: 'get_note',
user: xbUser,
topicid: qNoteID
},
dataType: 'jsonp',
jsonp: 'jsonp_callback',
success: function(data) {
if (jqDiv.parent().parent().css
('background-color').search(/^rgb/) == -1) {
jqDiv.data("orig_css", "rgb(230,
230, 230)");
} else {
jqDiv.data("orig_css",
jqDiv.parent().parent().css('background-color'));
}
qNoteResSuccess(data, jqDiv);
jqNote.css({
width: '100%',
backgroundColor: '#eeeeee',
border: '1px solid #009900'
});
}
});
--------------
Something like this. The key points are that it worked before, and it didn't change.
The point is that all the same code works, if I plug JQuery by 1st method ( document.getElementsByTagName('head')[0].appendChild(GM_JQ); ), but it fails to work, if I plug JQuery via @require tag.
The errors I get in the console:
Error: jsonp1250603530050 is not defined
Source File:
URL_TO_my_own_script.php?jsonp_callback=jsonp1250603530050&_=1250603531231&action=get_note&user=Vladimir+Mityukov&topicid=537110844
Line: 1
So, I've rolled back to the "old" way to plug JQuery. However, I'd like to switch to the "@require" once I get this problem resolved.
Please advise.
Note: the same bug-report was placed in greasemonkey's bug tracker, but still no effect:
Attachments (0)
Change History (2)
Changed December 10, 2009 03:13AM UTC by comment:1
Changed October 19, 2010 11:47PM UTC by comment:2
resolution: | → invalid |
---|---|
status: | new → closed |
Please note that this is an issue with the way Greasemonkey handles @require and the use of jQuery in it's extensions/user scripts. For further information on ways you can resolve this, see: http://forum.jquery.com/topic/importing-jquery-1-4-1-into-greasemonkey-scripts-generates-an-error or http://stackoverflow.com/questions/859024/how-can-i-use-jquery-in-greasemonkey. Thanks!.
From the description, this really sounds like a Greasemonkey issue. I tried visiting the site linked above with the bug report, but it seems to be down.