0

hey i am have made a form for product detail insertion . I am using ajax in asp.net in order to insert data in database. Now in my form of the controls is fileupload control. Problem is i dont know how to select the file and pass it to the static method for operations like hasfile, etc. so is it possible that i pass the file using ajax technique and can store it's detail in database.

<asp:FileUpload ID="file_image"   runat="server" />

$(document).ready(function () {

       $("#submit").click(function () {



           var cat = document.getElementById('DropDownList1').value;
           var nm = document.getElementById('name').value;
           var code = document.getElementById('code').value;
           var dt = document.getElementById('dt').value;

           var price = document.getElementById('price').value;
           alert("you clicked " + cat + " - " + nm + "-" + code + "-" + dt + "-" + price + "-");

           var fl = document.getElementById('file_image').value;
           //this line is the problem as i can't get file 
           $.ajax({

               method: "POST",
               contentType: "application/json", 
               url: "~/home.aspx/insert",
               dataType: "json",
              // data: "{'Name':'" + document.getElementById('name').value + "'}",
               data:"{}",
                //async: false,
                success: function (response) {
                   alert("User has been added successfully.");
                   window.location.reload();

               }

           });




       })


   });
Kam
  • 109
  • 7

1 Answers1

0

There are some issues with uploading files via ajax.

Ref. jQuery Ajax File Upload

You can do it as shown in the following link; however, it won't work in IE <= 9. http://blog.teamtreehouse.com/uploading-files-ajax

My recommendation if you want to upload multiple files would be to use something like http://www.uploadify.com/ with automatic fallback support. That way, you don't have to spend time programming that stuff yourself.

Community
  • 1
  • 1
user1477388
  • 20,790
  • 32
  • 144
  • 264