tags:

views:

110

answers:

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

edit: here is the php controller, in case it is relevant.

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

}

output of console.log(resp) with

    function symbol_handler(){
     fp.getForm().submit({
         url:'/index.php/ajax/test_function',
         success:function(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

Thanks, brandon

+1  A: 

according to the extjs 3.2.1 API (i don't know which version you are using), the success function is passed the following parameters:

  1. form : Ext.form.BasicForm The form that requested the action
  2. action : Ext.form.Action The Action class. The result property of this object may be examined to perform custom postprocessing.

Try to add the following to the success function to know what arguments are passed in the function:

console.log(arguments);
davyM
+2  A: 

The signature of the success-callback is function(form, action) where form is a reference to the form being submitted and action is the action object that has been submitted. It's either an instance of Ext.form.Action.Submit or Ext.form.Action.DirectSubmit (depending on whether you used Ext.direct). The action object gives access to a plenty of properties, among those is the result-property that contains the decoded response object. So, your ExtJS code should look like:

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