开发者

JQuery cross domain JSONP in FF5 extension/addon, callback not defined

开发者 https://www.devze.com 2023-03-23 11:20 出处:网络
Hi I am trying to create an extension for Firefox5 wherein the extension code injects two scripts on page load start.

Hi I am trying to create an extension for Firefox5 wherein the extension code injects two scripts on page load start.

var data = require("self").data;
var pageMod = require("page-mod");
pageMod.PageMod({
        include: ['*'],
            contentScriptWhen: "start",
            contentScriptFile:
        [data.url("jquery.min.js"), data.url("js_include.js")],
            });

The script js_include.js is doing a cross-domain JQuery jsonp call with a global callback function 'onJSONPLoad' and has code something like:

window.onJSONPLoad = function(data) {
      //do something here...
开发者_如何学C}

jQuery(function(){
        jQuery.ajax({
                url: 'http://localhost:8000/getvos/',
                    type: 'GET',
                    data: 'url='+window.location.href,
                    dataType: 'jsonp',
                    jsonp: 'jsonpCallback',
                    jsonpCallback: 'onJSONPLoad'
            });

    });

This works if I do it in a page, but not when I try to do it in the add-on. Firebug shows that the call was made, the response got, I can see the response in the console too. However, the function onJSONPLoad never executes and all I get is "onJSONPLoad is not defined".

I have seen other questions/answers on SO but they get as far as asking for onJSONPLoad to be global, which I have already done, but it still does not work.

Any help?


try this: jsonpCallback: 'window.onJSONPLoad'

0

精彩评论

暂无评论...
验证码 换一张
取 消