所以,我用FineUploader 3.3 MVC 4应用程序中,这是一个非常酷的插件,非常值得的名义成本。 谢谢这个建筑,是非常有用的。 现在,我只需要得到它正常工作。
我很新的MVC和绝对新传回JSON,所以我需要一些帮助得到这个工作。 下面是我使用的是什么,都在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 + '">');
}
}
}
}
编辑:使用Internet Explorer 9我一直,然后切换到Chrome浏览器,Firefox和我可以上传就好了。 有什么需要IE9的? 验证不起作用,无论浏览器。
端点火灾,以及文件/参数填充,所以这是所有好! 验证不会选择这个名单之外的东西阻止用户,但我可以用这方面的工作暂时。 我可以成功拯救,做什么,我需要用我上传的事,减去获得的onComplete火灾。 事实上,在IE中,我得到了我目前有一个打开/保存对话框。
问:是函数参数的onComplete(ID,文件名,responseJSON)得到的回报或出路填充? 我只是困惑这个问题。 难道我的JSON必须有它的这些参数,并填充?
我不这样做(填充这些参数),并在C#我的输出方法返回JsonResult这样看,刚刚回国的“成功”(如果适用):
return Json(new { success = true });
我是否需要添加更多? 这条线路是保存发生之后,和所有我想要做的就是告诉用户全部是好还是不好。 请问我的Json“成功”属性匹配与responseJSON.success?
我在想什么,或者有错吗? 我敢肯定,这将帮助其他人也一样,所以我希望你能花时间和协助。 我很感激! 谢谢。
Addressing the items in your question:
- 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.
- 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.
- 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.
- 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.
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 method not firing. Newbie, require some handholding