*I have a userscript with an jquery.ajax() call*:


































*// ==UserScript==// @name        myscripttest// @namespace   
myscripttest// @version     1// @include     *// @require     
http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js// 
@grant       GM_addStyle// @grant       GM_getResourceText// @grant         
none// ==/UserScript==var partNumber = "1234";var apiURL = 
"http://myapi.com"; var ajaxConfig = {        url: apiURL,        type: 
"POST",        data: {            'k': partNumber        },        
dataType: 'jsonp' }    var jqxhr = $.ajax( ajaxConfig )        
.done(function(msg) {            console.log( msg);        })        
.fail(function() {            alert( "error" );        })        
.always(function(w, x, y) {            console.log( "complete" );        
    console.log(x, y);        });*

I'm make the ajax call to an api on a domain which allows CORS 
(Access-Control-Allow-Origin: 
*).
If I'm playing in the security restricted sandbox (for ex needing 
GM_addStyle, or GM_getResourceText), my ajax calls to consume the jsonp are 
met with this error found in the console:

ReferenceError: jQuery18107040466994572055_1403112877434 is not defined

The log line in the .always() callback outputs this:

parsererror 
Error: jQuery18107040466994572055_1403112877434 was not called

If I simply avoid needing the custom GM_ functions and employ *@grant none *the 
call is performed as expected, returning a usable json object with no 
errors.  Though I have not used GM_addStyle in the example code, I would 
like to use it and others if I can.  It's a rather abitrary requirement to 
'need' $.ajax() as opposed to using the a gm_xmlhttprequest, but I'd prefer 
that part to be as portable as possible as this is rapid prototyping 
against a live site.  It may be a bit backwards, but the oddity remains.

So the main questions are:  

   - Why does a $.ajax() jsonp call not work in the greasemonkey sandbox 
   with GM_ functions, but does under the the @grant none condition?
   - Is there a "right way" to make this work?
   

I've tried multiple incantations and settings, but have yet to arrive at a 
solution.  Any help would be much appreciated.

-Ben

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/greasemonkey-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to