2010-06-22 78 views
0
function symbol_handler(){ 
    fp.getForm().submit({ 
    url:'/index.php/ajax/test_function', 
     success:function(resp){ 
     //how would i access attributes of the json object? 
    } 
}); 

編輯:這裏是php控制器,以防萬一它是相關的。extjs json decode

function test_function(){ 
$array = array(
    'success' => 'true', 
    'msg' => 'testing testing testing' 
    ); 
    echo json_encode($array); 

}

function symbol_handler(){ 
    fp.getForm().submit({ 
     url:'/index.php/ajax/test_function', 
     success:function(resp){ 
      console.log(resp); 
     } 
    }); 
    } 

輸出的console.log(RESP)的...

Object 
activeAction: null 
bodyStyle: "padding: 6px" 
buttons: Array (1) 
0: Object 
handler: function symbol_handler(){ 
hideParent: true 
minWidth: 75 
removeMode: "container" 
text: "GO" 
__proto__: Object 
length: 1 
__proto__: Array 
el: Object 
events: Object 
frame: true 
height: 100 
id: "ext-gen48" 
items: Object 
labelWidth: 40 
title: "Exercising textfields" 
width: 300 
__proto__: Object 

謝謝,布蘭登

回答

2

success -callback的簽名是function(form, action)其中form是對一個參考表單被提交,action是已提交的操作對象。它可以是Ext.form.Action.SubmitExt.form.Action.DirectSubmit的實例(取決於您是否使用Ext.direct)。 action對象提供了大量屬性,其中包括result-屬性,其中包含已解碼的響應對象。因此,您的ExtJS代碼應如下所示:

function symbol_handler(){ 
    fp.getForm().submit({ 
     url:'/index.php/ajax/test_function', 
     success:function(form, action){ 
      console.log(action.result); 
     } 
    }); 
} 
1

根據extjs 3.2.1 API(我不知道wh您正在使用)我的版本,成功函數傳遞參數如下:

  1. 形式:Ext.form.BasicForm該請求的操作形式
  2. 行動:Ext.form.Action行動類。該對象的結果屬性 可能會被檢查到 執行自定義後處理。

嘗試添加下列到成功的功能要知道在函數傳遞什麼樣的參數:

console.log(arguments);