2012-03-29 54 views
0

我是Sencha新手,正在从服务器读取响应JSON数据并在警报中显示,但在响应中,handleSuccess函数正在执行并获取警报中的数据未定义。所以我希望JSON中的消息数据显示在警报中。感谢您的帮助。从服务器如何读取Sencha触摸服务器中的响应json数据

JSON数据:

{ “数据”:[{ “成功”: “FALSE”, “消息”: “数据加载”, “groupCount”:0 “maxSeverity”: 10}]}

Ext.Ajax.request({ 

    url: 'serverurl', 

    headers: { 'Content-Type': 'application/json;charset=utf-8' }, 

    params: { 

     username: 'username', 

     password: 'password' 
    }, 

    method: 'GET', 

    success: handleSuccess, 

    failure: handleError 

}); 




    function handleSuccess(response, opts) 

{ 

    var jsonData = Ext.decode(response.Message); 

    alert(jsonData) 

} 

function handleError(response, opts) 

{ 

    alert('server-side failure with status code ' + response.status); 

} 

回答

0

使用下面的代码,使用response.responseText检索JSON对象

Ext.Ajax.request({ 
    url: URL, 
    defaultHeaders : 'application/json', 

    success : function(response, opt) { 
     // this will give you the JSON  
     Ext.Msg.alert('Success', response.responseText); 
    }, 

    failure : function(response, opt) { 
     Ext.Msg.alert('Failed', response.responseText); 
    } 
}); 

这个工作对我来说,它应该工作为你了。