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 ?

图片转代码服务由CSDN问答提供 功能建议

我的服务器上有一个php脚本,我从数据库获取vars,这个脚本返回一个像这个样本的json字符串 图片网址:

  [{'src':'imageurl1'},{'src':'imageurl2'},...] 
  <  / pre> 
 
 

在我的附加组件中,我将以下代码按请求检索

  var imgs;  
 
请求({
 
 url:“http://www.page.com/get.php”,
nnn onComplete:function(response){
 imgs = response.json; 
}  
 
}); 
   
 
 

并向'script.js'发送值

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

但它不起作用。 怎么了?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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?

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题