Question about uploading files using Jquery and sending to c# webmethod
I need to upload files using a Jquery call. Anyone have success doing this.
$("#chkBtn1").click(function () {
var daFile = $("#file1").prop("files")[0];
// Append form data
var form_data = new FormData();
form_data.append("file", daFile);
$.ajax({
url: "testFileLoad1.aspx/processImages",
//dataType: 'json',
cache: false,
contentType: "multipart/form-data",
processData: false,
data: form_data,
traditional: true, // Setting the data attribute of ajax with file_data
type: 'post',
success: function (response) {
alert('Success');
console.log(response);
},
error: function (response) {
alert('Error!');
console.log(response);
}
})
Would this be the correct syntax and also where can I find sample code to process the file in the Webmethod call. I've tried the sytnax below.
I've tried this but it appears to not process the file.
[WebMethod]
public static string processImages(HttpContext htp1)
{
string Files = htp1.Items.ToString();
HttpPostedFile f1 = htp1.Request.Files["file1"];
return "Successful"
}
Any ideas.