Hi, I need help on how I could upload .doc files using jQuery and Ajax to a folder in server. Below is my code: HTML: <input type="file" name="filename" id="filename"> JQuery jQuery.ajax({ type: "POST", url: "upload.aspx", data: "filename=" + $("#filename").val(), success: function(msg){ //do something } }) The upload.aspx contains the code to copy the file and save it on server. The problem is it is only getting the filename. I can't get the contents of the file. Kindly advise as my code above doesn't work. I need this done through JQuery-Ajax since I have scripts to run after the file upload. Thanks so much.
Hello! So you want to save the file to filesystem and then read it's contents? If so you need to save first and then read the Stream from the saved file. This would be done on the server with your upload.aspx code which would be in C# or VB. C# I hope : )
Yes, I want to save it to the filesystem. The only problem is the jquery data (data: "filename=" + $("#filename").val()) is only passing the filename to upload.aspx. I need to get the full filepath. How do I make it work (same as form submit) but using the JQuery-Ajax side (since I has scripts to process after file upload)?
Are you coding this from scratch or have something out-of-box? The JQuery-Ajax should post the file stream to your upload.aspx page. You won't be able to get the path for security reasons from the client. Ajax-Uploads can be tricky.
I'm coding it from scratch. I tried testing it with the ordinary form submit and it worked just fine. But when I transferred it to jQuery-Ajax, it only gets the filename and doesn't save the file on server. I need this done through jQuery though because I have scripts to run after creating the file. Is there any way I could upload files with jQuery-Ajax and with my upload .aspx?
You cannot passing the files using jQuery ajax,you need swfupload or iframe consider using this plugin https://github.com/johnlanz/jquery-fileuploader https://github.com/jfeldstein/jQuery.AjaxFileUpload.js