Search code examples
jsonformsextjsextjs4

extjs - How to submit a form when the response is not json?


I understand that when I submit a form, according to the documentation ExtJs by default parses the response as JSON.

In my case, the server returns HTML, that I want to display in a Panel. When I submit the from using getForm().submit(), ExtJs will throw an error about invalid JSON:

Ext.JSON.decode(): You're trying to decode an invalid JSON String

How can I tell ExtJs not to attempt to parse the response ? I could the access the text with the response object.


Solution

  • Finally, it was impossible for me to get to work the form.submit() of ExtJs. I needed an implementation using Ext. And since this is a frequent pattern in my application, it is important to have a short an simple solution.

    This is what I finally found (I have a modal window containing the form):

    var values = me.up('form').getValues(),
    panel = Ext.create('My.view.MyPanel', {
        xtype: 'panel',
        loader: {
            url: Paths.ajax + 'sav_vpc/douane.php',
            method: 'get',
            params: values,
            autoLoad: true
        }
    });
    me.up('window').close()
    

    This solution has another advantage over the me.up('form').getForm().submit() solution:

    While .getForm().submit() is asynchronous, .getValues() is synchronous. Therefore, it is possible to close the window immediately.