dongliang1223 2013-12-21 17:45
浏览 37
已采纳

使用请求mod使用firefox附加sdk检索json字符串中的变量

I have a php script on my server where i get vars from database and this script return a json string like this sample with images urls :

[ { 'src':'imageurl1'} , { 'src':'imageurl2'}, ... ]

In my add-on i put the following code to retrieve by request

var imgs; 

Request({

    url: "http://www.page.com/get.php",

    onComplete: function (response) {
        imgs = response.json;
    }

});

and send to a 'script.js' the values

pageMod.PageMod({

    include: "domain.com",
    contentScriptFile: data.url("script.js"),
    attachTo: ["top"],
    onAttach: function(worker) {
        worker.port.emit("imgs",imgs);
    }

});

But it dont work. Whats wrong ?

  • 写回答

1条回答 默认 最新

  • dswfyq6201 2013-12-23 19:12
    关注

    It's a slightly odd detail of the request module, you need to first create the request object ( as you did ) and then you need to call the get method on it:

    var imgs; 
    
    Request({
    
        url: "http://www.page.com/get.php",
    
        onComplete: function (response) {
            imgs = response.json;
        }
    }).get();
    // ^^^^^ <-- you need to call this method.
    

    Does that help?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样