Jquery AjaxUpload插件不会触发onComplete事件

时间:2011-08-18 11:07:42

标签: javascript jquery ajax asp.net-mvc-3 ajax-upload

我使用Valums AjaxUpload在我的ASP.NET MVC 3应用程序中上传文件。

new AjaxUpload($('input.partupload'), {
                autoSubmit: true,
                action: '/AdminPanel/Car/UploadPart',
                onSubmit: function (file, ext) {
                        if (!(ext && /^(zip)$/.test(ext.toLowerCase()))) 
                        {
                            $('#hinf').fadeIn('slow');
                            $('#hinf').html("Please, upload only Zip files!!");
                            return false;
                        } 
                    },
                data: { path: directoryPath,parentName : part, carId: @Model.carID, color: color },
                onComplete: function (file,response) {
                    var model = file.replace('.zip','');
                    if(response=="true")
                    {
                    alert(response);
                    createTree(part, model + '*' + part);
                    }
                    else
                    {
                    alert(response);
                    alert("Error during process");
                    }
                  }
            });

在我的控制器中我有

 HttpPostedFileBase file = Request.Files[0];
            if (...)
{
    //Here my alert fires and onComplete is OK
    return Content("true");


}
else
{
               //FAIL!!! Nothing is happened in OnComplete!!!!!!
                return Content("false");
}

所以,我不明白返回“真实”或“假”有什么区别......为什么我第一次看到结果,第二次看不到......需要你的帮助))) )

1 个答案:

答案 0 :(得分:0)

嗯,我弄清楚了...... 问题是在ajaxupload.js中出现了“false”值的错误,所以需要将“false”改为其他值!

所以,它完美无缺!!!

 HttpPostedFileBase file = Request.Files[0];
            if (...)
{

    return Content("true");


}
else
{
     //WORKS!!!!
     return Content("error");
}