Results 1 to 4 of 4

Thread: Redirecting to Web API after form submission.

  1. #1
    Sencha User
    Join Date
    Oct 2013
    Posts
    37
    Answers
    1

    Default Redirecting to Web API after form submission.

    I am uploading an image. This is the code of my view:

    Code:
    Ext.define('MyApp.view.AddCountry', {
        extend: 'Ext.window.Window',
        alias: 'widget.addcountry',
        closable: true,
        closeAction: 'destroy',
        modal: true,
        height: '28%',
        width: '45%',
        panelStatus: 'add',
        panelId: 0,
        initComponent: function () {
            var me = this;
            me.items = [{
                xtype: 'form',
                headers: { 'Content-Type': 'text/html' },
                standardSubmit: true,
                layout: 'form',
                bodyPadding: '5 5 0',
                itemId: 'addCountryForm',
                frame: false,
                items: [{
                    xtype: 'textfield',
                    fieldLabel: 'Name',
                    maxLength: 25,
                    enforceMaxLength: true,
                    allowBlank: false,
                    name: 'Matrix'
                }, {
                    xtype: 'textfield',
                    fieldLabel: 'Description',
                    maxLength: 100,
                    enforceMaxLength: true,
                    allowBlank: false,
                    name: 'description'
                }, {
                    xtype: 'filefield',
                    name: 'flagImage',
                    fieldLabel: 'Flag',
                    buttonText: 'Select Image...'
                }],
                buttons: [{
                    text: 'Save',
                    itemId: 'btnSaveCountry'
                }, {
                    text: 'Cancel',
                    itemId: 'btnCancelAdding'
                }]
            }];
            this.callParent();
        }
    });
    This is the upload code in my controller:

    Code:
    AddNewCountry: function (button) {
            var form = button.up('form').getForm();
            form.submit({
                url: 'localhost/myapp/api/country/addcountry',
                waitMsg: 'Please wait...',
                success: function (f, o) {
                    Ext.Msg.alert('Success', o.result.result);
                },
                failure: function (f, o) {
                    Ext.Msg.alert('Error', o.result.error);
                }
            });
        }
    When I submit the form, it gets redirected to "localhost/myapp/api/country/addcountry" that shows this string:


    {"$id":"1","success":true,"result":"Uploaded Successfully.","error":null}Can someone point out the error? If I remove "standardSubmit: true", The wait message keeps rendering. The control gets stuck there.

  2. #2
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    Does it work without the file field?

  3. #3
    Sencha User
    Join Date
    Oct 2013
    Posts
    37
    Answers
    1

    Default

    The problem was that my file handling controller was in a different project that used a different port than the port used by my ExtJS project. I had to use a new generic handler at ExtJS side and it worked perfectly. It was a cross domain issue. I still don't know how to enable CORS. Thanks anyways.

  4. #4
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    Glad to hear you dialed in on the problem. Here's a few links that might help you with CORS:
    http://docs.sencha.com/extjs/4.2.1/#...ction-cfg-cors
    http://enable-cors.org/

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •