本文介绍了jQuery AjaxUpload插件不会触发onComplete事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use Valums AjaxUpload for uploading file in my ASP.NET MVC 3 application .

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

所以,我不明白返回"true"或"false"的区别是什么...为什么我第一次看到结果,而第二次看不到...需要您的帮助))) )

So, I don't understand what is difference to return "true" or "false"... Why I see result at first time, and don't see at second... Need in your help))))

推荐答案

呵呵,我知道了...问题是在ajaxupload.js中,"false"值有问题,因此需要将"false"更改为其他值!

Huh, I figure out this...Problem is that in ajaxupload.js something wrong with "false" value, so what neeeded is to change "false" to something other value!!!

所以,它工作得很好!!!

So, it works perfectly!!!

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

    return Content("true");


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

这篇关于jQuery AjaxUpload插件不会触发onComplete事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-02 12:40