Jquery AjaxUpload plugin doesn't fire onComplete event

浪子不回头ぞ 提交于 2019-12-12 06:28:51

问题


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

In my controller I have

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

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


回答1:


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


来源:https://stackoverflow.com/questions/7106412/jquery-ajaxupload-plugin-doesnt-fire-oncomplete-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!