Extjs 4,文件上传

时间:2012-07-12 18:19:33

标签: extjs extjs4 filefield

我想使用Extjs4.1文件字段将文件发布到服务器。

但是发生错误,它说结果是未定义的。 :(

enter image description here

在表格中,

没有文件字段,它工作正常。'

这是表格。它加载好了。尝试提交时会发生错误。

var myform = Ext.create('Ext.form.Panel', {
    bodyStyle: 'padding: 15px 50px',
    defaults: {
        xtype: 'textfield',
        anchor: '100%',
        style : 'margin-top:10px'
    },
    items: [
    {
        xtype: 'fieldcontainer',
        layout: 'hbox',
        anchor: '50%',
        items: [
            {
                xtype: 'textfield',
                fieldLabel: '<b>Order Number </b>',
                name: 'orderNo',
                maxLength: 9,
                flex: 1,
                allowBlank: false
            }, {
                xtype: 'button',
                text: 'Get Info',
                name : 'getOrderInfo_btn',
                tooltip: 'Get Order Information',
                style: 'margin-left:5px',
                flex: 0
            }
        ]
    }, {
        fieldLabel: '<b>Refundable Tax Amount </b>',
        name: 'refundAmount',
        readOnly: true,
        labelWidth: 160,
        anchor: '45%',
        allowBlank: false
    }, {
        fieldLabel: '<b>Certificate File</b>',  //without this, it's OK
        xtype : 'filefield',  
        name: 'certificate',
        labelWidth: 160,
        anchor: '90%',
        allowBlank: false
    }
    .
    .
    .

这是我的控制者(提交表格),

refundTaxAmount: function (obj) {
        var form = obj.up('panel').down('form').getForm();
        console.log('Hi'); // it prints, but after that it stop with an error msg.
        if (form.isValid()) {
            form.submit({
                waitMsg: 'Please wait, now processing...',
                url: '/Order/CreditForTax/',
                method: 'POST',
                success: function (form, action) {
                    Ext.MessageBox.show({
                        title: 'Notice',
                        msg: 'The tax credit has been refunded!',
                        buttons: Ext.MessageBox.OK,
                        icon: Ext.MessageBox.INFO,
                        width: 300
                    });
                    form.reset();
                },
                failure: function (form, action) {
                    Ext.MessageBox.show({
                        title: 'Error',
                        msg: action.result.message,
                        buttons: Ext.MessageBox.OK,
                        icon: Ext.MessageBox.ERROR,
                        width: 300
                    });
                }
            });
        }
    }

有人知道,我的问题是什么?请指教我〜!

由于

[编辑]

当提交()时,在5-10秒后,会出现错误消息。

enter image description here

enter image description here

[EDIT2]

ASP.NET(c#)代码,

[HttpPost]
public JsonResult CreditForTax(RefundModel info, HttpPostedFileBase certificate)
{
    object result;
    try
    {
    //do something

    result = new {success = true};
    }
    catch (Exception e)
    {
    log.Error(e.Message +"\n"+e.StackTrace);
    result = new { success = false, message = e.Message };
    }

    return Json(result);
}
是的,我认为asp.net代码是错误的......有人知道该代码有什么问题吗?

1 个答案:

答案 0 :(得分:2)

如果服务器使用JSON发送返回对象,则必须将Content-Type标头设置为"text/html",以告知浏览器将文本未更改地插入到文档中体。

C#(MVC3)代码:

var jsonResponse = Json( new
                        {
                            success = false,
                            message = "Oops. There was an unexpected error.\n" + ex.ToString()
                        });
jsonResponse.ContentType = "text/html"; // <-- Set content type explicitly.
return jsonResponse;   

以下是documentation的链接。