Extjs4 - 表单提交始终返回失败

问题描述 投票:0回答:2

我正在使用ExtJS 4表单提交excel文件,但即使请求成功,它也会注册失败。什么是form.submit功能期待看到?

Console

形成

xtype: 'form',
name: 'upload_form',
items: [{
      text: 'File Upload',
      xtype: 'fileuploadfield',
      name: 'upload_btn',
      buttonOnly: true,
      hideLabel: true,
      allowBlank: false,
      clearOnSubmit: false
}]

调节器

'filter fileuploadfield[name="upload_btn"]': {
            change: this.UploadClick
        }
    ...
    UploadClick: function (vb, s) {
    var controller = this,
        form = controller.getUploadForm();

    if (form.isValid()) {
        form.submit({
            url: '/upload',
            waitMsg: 'Uploading your csv...',
            success: function (fp, o) {
                Ext.Msg.show({
                    title: 'Upload Complete',
                    msg: o.response.responseText,
                    icon: 'save-success',
                    buttons: Ext.Msg.OK
                });
            },
            failure: function (fp, o) {
                Ext.Msg.show({
                    title: 'Upload Error',
                    msg: o.response.responseText,
                    icon: Ext.MessageBox.ERROR,
                    buttons: Ext.Msg.OK
                });
            }
        });
    }
}

Java回归

Response.ResponseBuilder builder;
...
builder = Response.ok(null);
        return builder.build();
javascript forms extjs extjs4
2个回答
1
投票

不发送null Response ...但预期的JSON以及适当的内容类型标题:

String json = "{\"success\": true}";
return Response.ok(json, MediaType.APPLICATION_JSON).build();

1
投票

您需要在响应中附加参数success

E.g:

{
    "success":true, // note this is Boolean, not string
    "msg":"File uploaded"
}

如在文档中:https://docs.sencha.com/extjs/4.2.6/#!/api/Ext.form.Basic-method-submit

© www.soinside.com 2019 - 2024. All rights reserved.