Jquery AjaxUpload 插件不会触发 onComplete 事件

发布于 2024-11-30 08:36:43 字数 1563 浏览 3 评论 0原文

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2024-12-07 08:36:43

呵呵,我明白了这个...
问题是在 ajaxupload.js 中“false”值有问题,所以需要将“false”更改为其他值!

所以,它完美运行!

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

    return Content("true");


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

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");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文