2012-03-29 56 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); 
    } 
}); 

這個工作對我來說,它應該工作爲你了。