1. #1
    Sencha Premium Member
    Join Date
    Sep 2012
    Posts
    5
    Vote Rating
    0
    Masat0 is on a distinguished road

      0  

    Default Unanswered: error when form is submitting

    Unanswered: error when form is submitting


    I have form which submitted successfully, but I added filefield and got error:
    Uncaught exception: TypeError: Cannot convert 'result' to object
    Error thrown at line 221, column 8 in <anonymous function: onSuccess>(response) in /extjs/src/form/action/Submit.js?_dc=1357906359290:
    if (result !== true && !result.success)
    and object
    msg "You're trying to decode an invalid JSON String: "
    sourceClass "Ext.JSON"
    sourceMethod "decode"
    But form is sending.

    Code:
    Ext.define('App.view.admin.indicator.Edit' ,{
        extend: 'Ext.form.Panel',
        alias : 'widget.form_indicator_edit',
        
        padding: '0 15 0 5',
        autoScroll: true,    
        style: 'background-color: #fff;',
    
    
        defaults: {
            layout: {
                type: 'hbox',
                pack: 'start',
                align: 'stretch'
            },        
            padding: '15 0 0 0',
        },
        
        items: [
            {
                xtype: 'container',
                items: [
                        {
                            xtype: 'label',
                            html: 'Порядковый номер <span style="color: rgb(255, 0, 0); padding-left: 2px;">*</span>',
                            width: 150,
                        },
                        {
                            xtype: 'textfield',
                            name : 'index_number',
                            flex: 1,
                            allowBlank: false,
                            padding: '0 10 0 10',
                        },
                ],
            },    
            {
                xtype: 'container',
                items: [
                        {
                            xtype: 'label',
                            html: 'Файл',
                            width: 150,
                        },
                        {
                            xtype: 'filefield',
                            name : 'file_instruction',
                            flex: 1,
                            padding: '0 10 0 10',
                            buttonText: 'Выберите файл',
                            vtype: 'fileInstruction',
                        },
                ],
            },    
    
    
            {
                xtype: 'container',
                items: [
                        {
                            xtype: 'button',
                            text: 'Сохранить',
                            action: 'save'
                        },  
                ],
            },    
        ]
    });
    in controller I use form.submit().

    Which options should I set in method submit that I can submit the form without this error?

  2. #2
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    I don't see a url property in your form configuration. Are you specifying the url in the body of the form.submit() method?

    The error you're reporting sounds as if the server-side response is not in a JSON format or is returning something unexpected.

  3. #3
    Sencha Premium Member
    Join Date
    Sep 2012
    Posts
    5
    Vote Rating
    0
    Masat0 is on a distinguished road

      0  

    Default


    Yes, I specify url in the body form.submit.

    I check server-side
    Code:
    echo json_encode(array("success" => true, "message" => 'test' ));
    exit;
    When I use form without filefield there is not error. When I add filefield, I get error and get reply from server.

  4. #4
    Sencha - Community Support Team friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106
    Vote Rating
    27
    friend has a spectacular aura about friend has a spectacular aura about

      0  

    Default


    Is your server-side code doing multipart/form-data handling?

  5. #5
    Sencha Premium Member
    Join Date
    Sep 2012
    Posts
    5
    Vote Rating
    0
    Masat0 is on a distinguished road

      0  

    Default


    I try test.
    app.js
    Code:
    Ext.application({
        requires: ['Ext.container.Viewport'],
        name: 'AM',
        appFolder: 'app',
    
    
        controllers: [
            'Test'
        ],
       
        launch: function() {
            Ext.create('Ext.container.Viewport', {
                layout: 'fit',
                items: [
                    {
                        xtype: 'testform',
                    }
                ]
            });
        }
    });

    view TestForm.js
    Code:
    Ext.define('AM.view.TestForm' ,{    
    	extend: 'Ext.form.Panel',
        alias : 'widget.testform',
        
        padding: '0 15 0 5',
        autoScroll: true,    
        style: 'background-color: #fff;',
        id: 'form_id',
    
    
    
    
        defaults: {
            layout: {
                type: 'hbox',
                pack: 'start',
                align: 'stretch'
            },        
            padding: '15 0 0 0',
        },
        
        items: [
            {
                xtype: 'container',
                items: [
                        {
                            xtype: 'label',
                            html: 'test <span style="color: rgb(255, 0, 0); padding-left: 2px;">*</span>',
                            width: 150,
                        },
                        {
                            xtype: 'textfield',
                            name : 'index_number',
                            flex: 1,
                            allowBlank: false,
                            padding: '0 10 0 10',
                        },
                ],
            },  
            {
                xtype: 'container',
                items: [
                        {
                            xtype: 'label',
                            html: 'file',
                            width: 150,
                        },
                        {
                            xtype: 'filefield',
                            name : 'file_instruction',
                            flex: 1,
                            padding: '0 10 0 10',
                            buttonText: 'select file',
                        },
                ],
            },   
            {
                xtype: 'container',
                items: [
                        {
                            xtype: 'button',
                            text: 'Save',
                            action: 'save'
                        },  
                ],
            },    
        ]
    });

    controller Test.js
    Code:
    Ext.define('AM.controller.Test', {    
    	extend: 'Ext.app.Controller',
    
    
        views: [
            'TestForm'
        ],
        
        init: function() {
            this.control({
                'testform button[action=save]': {
                    click: this.testSendForm
                }, 
            });
        },
        
        testSendForm: function() {
            var form = Ext.getCmp('form_id').getForm();
    
    
    
    
            if(form.isValid()) {
                
                form.submit({
                    waitMsg:'Данные сохраняются...',
                    timeout: 30,
                    url: 'response.php',
                    success: function(form, action) {
                        console.log('success '+action.response.responseText);
                    },
                    failure: function(form,action){
                        console.log(action.response.responseText);
                    }
                });
            } 
        },
    });

    server-side response.php
    Code:
    <?php 
    echo json_encode(array("success" => true, "message" => 'test' ));
    exit;
    ?>

    When I comment filefield in view, I get
    {"success":true,"message":"test"}
    in console. When I use filefield, I get
    Uncaught exception: Ext.Error: You're trying to decode an invalid JSON String:
    ...
    Ext.Error.raise({sourceClass:"Ext.JSON",sourceMethod:"decode",msg:"You're trying to decode an invalid JSON String: "+json})
    and
    {"success":true,"message":"test"}
    The form was sent and the reply was recieved inspite of this error. I don't have any ideas.

  6. #6
    Sencha Premium Member
    Join Date
    Sep 2012
    Posts
    5
    Vote Rating
    0
    Masat0 is on a distinguished road

      0  

    Default


    Ok. I ran example "File Upload Field" from sencha docs and I got same error. I inserted console.log in form/action/Submit.js and I got two output. The first is emty string, the second is that php echo send from server. Why when I use filefield in form then Submit.js is called twice?

    I check that this error occurs in opera 12.01 on Linux. There is not error in FF and Chrome

Thread Participants: 1

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar