FineUploader OnComplete方法不触发。新手,需要一些扶持 [英] FineUploader OnComplete method not firing. Newbie, require some handholding

查看:1708
本文介绍了FineUploader OnComplete方法不触发。新手,需要一些扶持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我在一个MVC 4应用程序中使用FineUploader 3.3,这是一个非常酷的插件,非常值得的名义成本。感谢建设这个,非常有用。现在,我只需要让它正常工作。

So, I'm using FineUploader 3.3 within a MVC 4 application, and this is a very cool plugin, well worth the nominal cost. Thanks for building this, very useful. Now, I just need to get it working correctly.

我是新的MVC和绝对新的JSON传回,所以我需要一些帮助,使这工作。这里是我正在使用,所有在doc.ready。

I'm pretty new to MVC and absolutely new to passing back JSON, so I need some help getting this to work. Here's what I'm using, all within doc.ready.

var manualuploader = $('#files-upload').fineUploader({
request:
{
    endpoint: '@Url.Action("UploadFile", "Survey")',
    customHeaders: { Accept: 'application/json' },
    params: {
        //variables are populated outside of this code snippet
        surveyInstanceId: (function () { return instance; }),
        surveyItemResultId: (function () { return surveyItemResultId; }),
        itemId: (function () { return itemId; }),
        imageLoopCounter: (function () { return counter++; })
    },
    validation: {
        allowedExtensions: ['jpeg', 'jpg', 'gif', 'png', 'bmp']
    },
    multiple: true,
    text: {
        uploadButton: '<i class="icon-plus icon-white"></i>Drop or Select Files'
    },                              
    callbacks: {
        onComplete: function(id, fileName, responseJSON) {
            alert("Success: " + responseJSON.success);
            if (responseJSON.success) {
                $('#files-upload').append('<img src="img/success.jpg" alt="' + fileName + '">');
                }
            }
    }
}

b>编辑:我一直在使用Internet Explorer 9,然后切换到Chrome,Firefox和我可以上传就好了。 IE9需要什么?验证不工作,不管浏览器。

I had been using Internet Explorer 9, then switched to Chrome, Firefox and I can upload just fine. What's required for IE9? Validation doesn't work, regardless of browser.

端点触发,文件/参数被填充,所以这一切都很好!验证不会阻止用户选择此列表之外的内容,但我可以暂时使用此功能。我可以成功地保存和做我需要做的与我的上传,减去OnComplete的火。实际上,在IE中,我得到一个打开/保存对话框与我目前的。

Endpoint fires, and file/parameters are populated, so this is all good! Validation doesn't stop a user from selecting something outside of this list, but I can work with this for the time being. I can successfully save and do what I need to do with my upload, minus getting the OnComplete to fire. Actually, in IE, I get an OPEN/SAVE dialog with what I have currently.

问题:是onComplete(id,filename,responseJSON)由回报还是出路?我只是困惑这个。我的JSON必须有这些参数,并填充?

Question: Are the function parameters in onComplete (id, filename, responseJSON) getting populated by the return or on the way out? I'm just confused about this. Does my JSON have to have these parameters in it, and populated?

我不这样做(填充这些参数),我的输出方法在C#返回JsonResult看(如果合适):<​​/ p>

I don't do this (populate those parameters), and my output method in C# returns JsonResult looking like this, just returning 'success' (if appropriate):

return Json(new { success = true });  

我需要添加更多吗?这行是在保存发生后,所有我想做的是告诉用户一切都是好或不。我的Json中的success属性是否与responseJSON.success匹配?

Do I need to add more? This line is after the saving takes place, and all I want to do is tell the user all is good or not. Does the 'success' property in my Json match up with the responseJSON.success?

我失去了什么,还是错了?我相信这会帮助别人,所以我希望你会花时间和帮助。我很感激!感谢。

What am I missing, or have wrong? I'm sure this would help others too, so I hope you'll take the time and assist. I appreciate it! Thanks.

推荐答案

解决问题中的项目:


  1. 对于选择文件对话框中的限制,还必须设置 acceptFiles 验证选项。请参阅 验证选项部分自述

  2. 您的验证选项属性位置错误。它不应该在请求属性/选项下。对于文本多个回调也是如此。选项/属性。

  3. IE中的打开/保存对话框是由您的服务器未返回带有正确Content-Type的响应而导致的标题。您的回复的Content-Type应为text / plain。有关详细信息,请参见服务器端自述

  4. 在处理响应客户端时,您的服务器在其响应中返回的任何内容都将由Fine上传者使用 JSON.parse 进行解析。在您的服务器响应中调用 JSON.parse 的结果将作为 responseJSON 参数传递到您的 onComplete 回调处理程序。如果您要将特定信息从服务器传递到客户端代码(例如,您可能希望显示客户端代码的某些文本,上传文件的新名称等),则可以通过向您的服务器响应。然后,您的 onComplete 处理程序中将提供此数据。如果你没有任何需要,你可以简单地返回你当前返回的成功响应。我已链接到的服务器端自述文件提供了有关所有这些的更多信息。

  1. Regarding restrictions inside of the "select files" dialog, you must also set the acceptFiles validation option. See the validation option section in the readme for more details.
  2. Your validation option property in the wrong place. It should not be under the request property/option. The same is true for your text, multiple, and callbacks options/properties. Also, you are not setting your callbacks correctly for the jQuery plug-in.
  3. The open/save dialog in IE is caused by your server not returning a response with the correct "Content-Type" header. Your response's Content-Type should be "text/plain". See the server-side readme for more details.
  4. Anything your server returns in it's response will be parsed by Fine Uploader using JSON.parse when handling the response client-side. The result of invoking JSON.parse on your server's response will be passed as the responseJSON parameter to your onComplete callback handler. If you want to pass specific information from your server to your client-side code, such as some text you may want to display client-side, the new name of the uploaded file, etc, you can do so by adding appropriate properties to your server response. This data will then be made available to you in your onComplete handler. If you don't have any need for this, you can simply return the "success" response you are currently returning. The server-side readme, which I have linked to, provides more information about all of this.

要澄清我在#2,您的代码应如下所示:

To clarify what I have said in #2, your code should look like this:

$('#files-upload').fineUploader({
   request: {
       endpoint: '@Url.Action("UploadFile", "Survey")',
       customHeaders: { Accept: 'application/json' },
       params: {
           //variables are populated outside of this code snippet
           surveyInstanceId: (function () { return instance; }),
           surveyItemResultId: (function () { return surveyItemResultId; }),
           itemId: (function () { return itemId; }),
           imageLoopCounter: (function () { return counter++; })
       }
   },
   validation: {
       allowedExtensions: ['jpeg', 'jpg', 'gif', 'png', 'bmp']
   },
   text: {
       uploadButton: '<i class="icon-plus icon-white"></i>Drop or Select Files'
   }
})
   .on('complete', function(event, id, fileName, responseJSON) {
       alert("Success: " + responseJSON.success);
       if (responseJSON.success) {
          $('#files-upload').append('<img src="img/success.jpg" alt="' + fileName + '">');
       }
   });                              

这篇关于FineUploader OnComplete方法不触发。新手,需要一些扶持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆