1

i want to create a fileupload with ajax and jquery.i send formData to server.i can not get data and save image on server. it is my code in javascript:

function UploadFile() {
         var fileName = $('#uploadFile').val().replace(/.*(\/|\\)/, '');
         if (fileName != "") {
             var formData = new FormData();

             formData.append('file', $('input[type=file]')[0].files[0]);
             $.ajax({
                 url: 'p1.aspx/uploadPic',
                 data: formData,

                 processData: false,
                 contentType: false,
                 type: 'POST',
                 success: function (dt) {
                     alert(dt.d);
                 }
             });
             }
     }

code in p1.aspx page:

[WebMethod]
public static string uploadPic(HttpPostedFile file)
{
 return file.FileName;
}

it is not work and not return any thing!what is wrong?how can get image on server? best reagrds.

user3651326
  • 122
  • 9
  • Refer this http://stackoverflow.com/questions/2320069/jquery-ajax-file-upload?rq=1 – User Apr 12 '16 at 11:55
  • thanks.i read and execute all!but i can not do it in C#.server code in examples is in php.can you explain for me.how can do it and what is wrong? – user3651326 Apr 12 '16 at 12:10

0 Answers0