2014-01-29 44 views
0

我用ajax解决了一个使用延迟函数的同步问题。 我现在收到一个响应,现在有一个大的对象与statusResponse等内部。提取响应对象JSON

我的JSONP对象也成功存储在responseJSON对象中。我如何提取它或将它保存在另一个变量中?

var web = new webService(); 
web.init(app.info); 

,这里的类

function webService() { 
    this.init = function(app) { 
     var d = this.connect(app).done(function(){}); 
     console.log(d); 
    } 

    this.connect = function(app) { 
     console.log(app); 

     return $.ajax({ 
      url: 'working url', 
      dataType: 'jsonp', 
      jsonp: 'jsoncallback', 
      timeout: 5000 
     }); 
    } 
} 
+0

您能否重新解释这个问题? – Rui

+0

有什么问题?你想从哪里访问数据? –

+1

你期望'console.log(d)'输出什么? – crush

回答

2

.done()将被调用的时候,数据已经返回(而是通过参数)。所以,确保你添加一个参数到你的回调函数,然后检查它是否你想要的。

this.connect(app).done(function(mydata){ 
    // mydata = the response object 
    // grab whatever information you want from it here. 
});