Extjs4-表单提交总是返回失败

时间:2019-03-25 15:03:13

标签: javascript forms extjs extjs4

我正在使用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();

2 个答案:

答案 0 :(得分:1)

您需要附加参数success作为响应:

例如:

{
    "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

答案 1 :(得分:1)

不要发送null Response ...但是要发送期望的JSON以及适当的内容类型标头:

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