c# - File upload using ajax request -


i trying upload image, using ajax. sending request this:

@using (ajax.beginform("savereferral", "referralim", new ajaxoptions {     httpmethod = "post",     onsuccess = "onsuccessreferralsent" }, new { id = "frmreferral", onsubmit = "oncontrolmapping(this);" })) { 

}

if send request this:

 @using (html.beginform("savereferral", "referralim", formmethod.post, new { id = "frmreferral", enctype = "multipart/form-data" }))    {  

file uploaded successfully, want use ajax ,please me how should file uploading ajax. thanks

i not using mvc if want use $.ajax here is...

$('.file-uploadid').on('click', function (e) {             e.preventdefault();             var fileinput = $('.file-uploadid');             var filedata = fileinput.prop("files")[0];   // getting properties of file file field             formdata.append("file", filedata); // appending parameter named file properties of file_field form_data             formdata.append("user_email", email); //adding email address parameter if have             $.ajax({                   url: '/fileuploadhandler.ashx',                   data: formdata,                   processdata: formdata.processdata,                   contenttype: formdata.contenttype,                   type: 'post',                   success: function (data) {                         var obj = $.parsejson(data);                         if (obj.statuscode == "ok") {                               alert("file upload done");                         } else if (obj.statuscode == "error") {                               alert("file upload error");                         }                   },                   error: function (errordata) {                         $('.result-message').html("there problem uploading file. please try again.").show();                   }             });       });  

handler

public void processrequest(httpcontext context)   {         context.response.contenttype = "text/plain";         context.response.expires = -1;         var email = context.request.params["user_email"];         var filedata = context.request.files["file"];         try         {              var result =  uploadimagetoserver(email, filedata);               context.response.write(result);         }         catch (exception ex)         {               context.response.write("error while uploading file server, please try again.");         }   } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -