0

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.

2
  • 1
    Don't you think that AJAX will be more suitable here?
    – Damask
    Dec 10, 2013 at 10:51
  • I could change the server's response into {html: '<my html bribe>'}. But if it's possible to change the client side, I'd prefer. Dec 10, 2013 at 12:18

3 Answers 3

2

I don't know if you are looking for strictly an ExtJS framework solution. However, it seems you may be able to solve your issue possibly using xmlhttprequest directly since you are looking to push the html returned directly to dom?

var xmlhttp = new XMLHttpRequest();
xmlhttp.open('GET','/myPath/here',false);
xmlhttp.send();
var html = xmlhttp.responseText;
//assign value
1
0

In Ext.form.Basic configuration you can define your own reader and errorReader

1
  • This doesn't really help, because there are only ajax, array and xml readers. There is nothing simpler, and I don't think I'm ready to write my own extension Ext.data.reader.Html. I think getForm().submit() isn't the right approach to the problem. Dec 10, 2013 at 15:13
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.