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

末鹿安然 提交于 2019-12-13 04:35:24

问题


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.


回答1:


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



回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/20491378/extjs-how-to-submit-a-form-when-the-response-is-not-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!