-
11 Jan 2013 4:11 AM #1
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:
and objectUncaught 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)But form is sending.msg "You're trying to decode an invalid JSON String: "
sourceClass "Ext.JSON"
sourceMethod "decode"
in controller I use form.submit().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' }, ], }, ] });
Which options should I set in method submit that I can submit the form without this error?
-
11 Jan 2013 5:14 AM #2
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.
-
11 Jan 2013 5:38 AM #3
Yes, I specify url in the body form.submit.
I check server-side
When I use form without filefield there is not error. When I add filefield, I get error and get reply from server.Code:echo json_encode(array("success" => true, "message" => 'test' )); exit;
-
11 Jan 2013 6:25 AM #4
Is your server-side code doing multipart/form-data handling?
-
11 Jan 2013 1:29 PM #5
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 getin console. When I use filefield, I get{"success":true,"message":"test"}andUncaught 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})The form was sent and the reply was recieved inspite of this error. I don't have any ideas.{"success":true,"message":"test"}
-
13 Jan 2013 10:17 AM #6
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


Reply With Quote