【问题标题】:Extjs4, File uplaodExtjs4,文件上传
【发布时间】:2012-07-12 18:19:32
【问题描述】:

我正在尝试使用 Extjs4.1 文件字段将文件发布到服务器。

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

形式上,

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

这是表格。它加载正常。尝试提交时出现错误。

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
                    });
                }
            });
        }
    }

谁知道,我的问题是什么?请指教~!

谢谢

[编辑]

submit() 时,5-10 秒后出现错误信息。

[编辑2]

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 代码是错误的...有人知道该代码有什么问题吗?

【问题讨论】:

  • 您能否说明错误是在提交表单之前发生还是文件被提交到服务器但响应没有被正确解析?
  • no之前提交出错,所以最后发不出去。
  • 调用堆栈是什么样的?它在做什么以及错误实际发生在哪里?
  • @DmitryB 我只是用更详细的错误消息编辑我的问题,请您查看我的问题吗?谢谢!
  • 看起来错误正在处理响应中 - 因此此时必须已联系服务器。您能否验证服务器代码是否按预期处理以及服务器响应的返回是什么样的?

标签: extjs extjs4 filefield


【解决方案1】:

如果服务器使用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的链接。

【讨论】:

    猜你喜欢
    • 2013-11-08
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 2013-12-19
    相关资源
    最近更新 更多