extjs - 当响应不是json时如何提交表单? [英] extjs - How to submit a form when the response is not json?
问题描述
我明白当我提交表单时,根据文档 ExtJs默认情况下解析响应为JSON。
I understand that when I submit a form, according to the documentation ExtJs by default parses the response as JSON.
在我的情况下,服务器返回HTML,我想显示在一个小组。当我使用 getForm()。submit()
提交时,ExtJs会抛出一个有关无效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
如何告诉ExtJs不尝试解析响应?我可以使用响应对象。
How can I tell ExtJs not to attempt to parse the response ? I could the access the text with the response object.
推荐答案
最后,我不可能去工作 form.submit()
的ExtJs。我需要使用 Ext
实现。而且由于这是我应用程序中频繁的模式,所以重要的是要有一个简单的解决方案。
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()
此解决方案具有另一个优势通过 me.up('form')。getForm()。submit()
解决方案:
This solution has another advantage over the me.up('form').getForm().submit()
solution:
code> .getForm()。submit()是异步的, .getValues()
是同步的。因此,可以立即关闭窗口。
While .getForm().submit()
is asynchronous, .getValues()
is synchronous. Therefore, it is possible to close the window immediately.
这篇关于extjs - 当响应不是json时如何提交表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!