javascript Extjs如何在没有ajax的情况下提交表单?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10893947/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 11:24:07  来源:igfitidea点击:

Extjs how submit form without ajax?

javascriptajaxextjsextjs4form-submit

提问by vedmed

Good day! I am try submit extjs form without ajax and show result on the next page. This is my code:

再会!我尝试在没有 ajax 的情况下提交 extjs 表单并在下一页显示结果。这是我的代码:

Ext.define('test.from', {
    extend: 'Ext.form.Panel',
    alias: 'widget.test.form',
    initComponent: function () {

        var me = this;

        Ext.apply(this, {
            frame: true,
            bodyPadding: 7,
            border: 0,
            items: [{
                xtype: 'textfield',
                fieldLabel: 'First Name',
                name: 'contact_attr'
            }, {
                xtype: 'textfield',
                fieldLabel: 'Last Name',
                name: 'contact_attr'
            }],
            buttons: [{
                text: 'Send',
                handler: function () {
                    me.getForm().submit({
                        url: '/salary/public/auth/',
                        standardSubmit: true,
                        method: 'POST'
                    });
                }
            }]
        });

But redirect to other page doesn't occur and I receive error: You're trying to decode an invalid JSON String. Can anybody help me? Thank you!

但是重定向到其他页面不会发生,我收到错误:You're trying to decode an invalid JSON String。有谁能够帮我?谢谢!

回答by Egy Mohammad Erdin

ok, so you have 2 error.

好的,所以你有 2 个错误。

  1. why not redirect(standarssubmit), and
  2. why you got "error decode"
  1. 为什么不重定向(标准提交),以及
  2. 为什么你得到“错误解码”

i guess you're using extjs4:

我猜你正在使用 extjs4:

1 . From the docs api. it say that submit()method is Shortcut to do a submit action. and the parameter is The options to pass to the action (see doAction for details). so, putting standardSubmitto submitmethod isn't the correct way. there is no standardSubmit option. more info. myanswer, you have 2 alternative way.
first, use the init:

1 . 来自文档 api。它说那个submit()方法是Shortcut to do a submit action。并且参数是The options to pass to the action (see doAction for details)。因此,把standardSubmitsubmit方法是不正确的方法。没有标准提交选项。更多信息。我的回答,您有 2 种替代方法。
首先,使用初始化:

Ext.apply(this,{
    standardSubmit:true,  // not working...
    frame: true,
    bodyPadding: 7,
    .......


Edits:

编辑:

.......
me.getForm().standardSubmit=true; //just like OP comment
me.getForm().submit({
   url: '/salary/public/auth/',
   standardSubmit: true,
   method: 'POST'
});
.......


second, use doAction:

其次,使用doAction:

...
me.getForm().doAction('standardsubmit',{
   url: '/salary/public/auth/',
   standardSubmit: true,
   method: 'POST'
});
...

2 . the error decode, i don't know what is your salary/public/authlook like....
try my first solution, if error exists, it mean the error is somewhere else...

2 . 错误解码,我不知道你的salary/public/auth样子......
尝试我的第一个解决方案,如果存在错误,则意味着错误在其他地方......