AJax技术

FileUpload using Jquery Ajax and Generic Handler

字号+ 作者:H5之家 来源:H5之家 2017-02-20 08:03 我要评论( )

Hi to all im a beginner in asp.net fileUploader and im using blow code to upload:[嗨,我在ASP.NET fileuploader初学者,我用吹代码上传:]

I was a little confused with jQuery-File-Upload myself, but after reviewing the plugin documentation I found what is needed for the plugin to work on Windows environment.

PROBLEM 1: FILE SAVING - regarding this issue, make sure that you are saving to a valid and previously created directory, and also that you have WRITE permissions to that directory.

PROBLEM 2: UPLOAD POSTBACK - You must setup your upload script to write the uploaded file, AND return a valid JSON response to the plugin, as defined on the plugin documentation:

if (context.Request.Files.Count > 0) { HttpFileCollection files = context.Request.Files; for (int i = 0; i < files.Count; i++) { HttpPostedFile file = files[i]; string fname = context.Server.MapPath("~/uploads/" + file.FileName); file.SaveAs(fname); } } upload_response = '{"files":[{"name": ' + file.FileName + '","size":' file.FileSize + ',"url":"http:\/\/example.org\/files\/ + file.FileName + ",' upload_response =+ '"thumbnailUrl": "http:\/\/example.org\/files\/thumbnail\/ + file.FileName + ","deleteUrl": "http:\/\/example.org\/files\/ + file.FileName + ",' upload_response =+ '"deleteType": "DELETE"}]}"' context.Response.ContentType = "application/json"; context.Response.Write( upload_response );

Please note that I also changed the ContentType to "application/json". The syntax of this code may not be complete, but the most important is to output these JSON fields required by the plugin.

Good Luck!

Ferdi

我有点困惑,jQuery文件上传自己,但在回顾我所发现的是插件工作在Windows环境下所需要的插件文件。

问题1:文件保存-关于这个问题,确保您保存到一个有效的和先前创建的目录,而且你要那个目录的写权限。

问题2:上传回你必须设置你的上传脚本写的上传的文件,并返回一个有效的JSON响应的插件,在插件文件定义:

if (context.Request.Files.Count > 0) { HttpFileCollection files = context.Request.Files; for (int i = 0; i < files.Count; i++) { HttpPostedFile file = files[i]; string fname = context.Server.MapPath("~/uploads/" + file.FileName); file.SaveAs(fname); } } upload_response = '{"files":[{"name": ' + file.FileName + '","size":' file.FileSize + ',"url":"http:\/\/example.org\/files\/ + file.FileName + ",' upload_response =+ '"thumbnailUrl": "http:\/\/example.org\/files\/thumbnail\/ + file.FileName + ","deleteUrl": "http:\/\/example.org\/files\/ + file.FileName + ",' upload_response =+ '"deleteType": "DELETE"}]}"' context.Response.ContentType = "application/json"; context.Response.Write( upload_response );

请注意,我也改变了contentType“application/json”。此代码的语法可能不完整,但最重要的是输出这些领域所需的JSON插件。

祝你好运!

Ferdi

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • 技术分享:asp.net+Ajax根据滚动条动态异步加载数据

    技术分享:asp.net+Ajax根据滚动条动态异步加载数据

    2017-02-15 12:01

  • 基于(Ajax+Linq)技术增删改查源码,学教实践,Asp.net源码

    基于(Ajax+Linq)技术增删改查源码,学教实践,Asp.net源码

    2017-02-09 17:03

  • .NET中web开发技术的新革命(ASP.NET2.0,AJAX,Silverlight)

    .NET中web开发技术的新革命(ASP.NET2.0,AJAX,Silverlight)

    2017-02-09 16:00

  • asp.net实现无刷新ajax技术登录界面

    asp.net实现无刷新ajax技术登录界面

    2017-02-08 10:04

网友点评