Search code examples
javascriptformsextjsextjs4

Extjs4 - Form submit always returns a failure


I'm submitting an excel file using an ExtJS 4 form but even when the request is successful it registers a failure. What is the form.submit function expecting to see?

Console

Form

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

Controller

'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 return

Response.ResponseBuilder builder;
...
builder = Response.ok(null);
        return builder.build();

Solution

  • don't send a null Response ...but the expected JSON along with a proper content-type header:

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