user2783460
user2783460

Reputation: 11

EXTJS 4 How to get Json response back on success of submit in form?

I am able to see the json response in firebug , but when i decode the ACTION of form on success its giving undefined .

{
    xtype: 'form',
    x: 30,
    y: 520,
    height: 80,
    bodyPadding: 10,
    title: 'myuploadform',
    fileUpload: true,
    standardSubmit: false,
    autoHeight: true,
    bodyStyle: 'padding: 10px 10px 10px 10px;',
    labelWidth: 50,

    items:[{
        xtype: 'fileuploadfield',
        id: 'filedata',
        emptyText: 'Select a document to upload...',
        fieldLabel: 'File',
        buttonText: 'Browse'
    }],

    buttons: [{
        text: 'Upload',
        handler: function() {
            var form = this.up('form').getForm();
            if(form.isValid()){
                alert("submit");

                form.submit({
                    url: 'myurl'
                    waitMsg: 'Uploading file...',

                    success: function (form,action) {
                        var data= Ext.JSON.decode(action.response.responseText);
                        alert("Success: " + data.msg);
                        Ext.Msg.alert('Success', action.result.message);
                    },

                    failure: function (form, action) {
                        var data = Ext.decode(action.response.responseText);
                        alert("Failure: " + data.msg);
                    }
                });
            }
        }
    }]
}

My url returns json response i want to handle it in success of submit . If someone tried it pls let me know

Upvotes: 1

Views: 17162

Answers (2)

Siva
Siva

Reputation: 8058

try plain JavaScript way

var data= JSON.parse(action.response.responseText);

or ExtJs 3.x way

var data= Ext.util.JSON.decode(action.response.responseText);

for ExtJs 4 and above

var data= Ext.JSON.decode(action.response.responseText);

Upvotes: 4

Surya Prakash Tumma
Surya Prakash Tumma

Reputation: 2193

         success : function(response, opts)
            {
                response = Ext.decode(response.responseText);
                if(response.success==true){
                    alert("Authentication sucess");

                }else{

                    Ext.MessageBox.alert('Alert','Invalid User name or password');
                }


            },
    failure:function(response, opts)
              {
                  Ext.MessageBox.alert('Alert','Exception is occured please contact administrator');


              }

Upvotes: 1

Related Questions