I am uploading files to my app and i'am using ajax & jqyery & handel in asp.net this my code jqyery
$(document).ready(function ()
{
$('#Button1').click(function ()
{
var files = $('#FileUpload1')[0].files;
if (files.length > 0) {
var id = 1;
var formData = new FormData();
for (var i = 0; i < files.length; i++) {
formData.append(files[i].name, files[i]);
}
$.ajax({
url: 'Handler1.ashx',
method: 'Post',
data: formData,
contentType: false,
processData: false,
success: function () {
alert('success');
},
error: function (err) {
alert(err.error)
}
});
}
});
});
and this my code in handler c#
public void ProcessRequest(HttpContext context)
{
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
string fileName = context.Server.MapPath("~/Uploads/" + System.IO.Path.GetFileName(file.FileName));
file.SaveAs(fileName);
}
}
}
My problem is i need to pass a other variable like id from my jquery to handler someone have any suggestion please
Just do the FormData.Append in your javascript
formData.append('id', 'test1234');
And in your handler access it via Form
var otherData = context.Request.Form;
Happy coding, cheers!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.