If you're using
a modern browser[
^], you can use
the FormData
class[
^] to upload the file:
function ChooseFileFunction() {
var fileToUpload = document.getElementById('<%= FileUpload1.ClientID %>');
$.ajax({
type: 'POST',
url: 'MyWebService.asmx/UploadImages',
data: new FormData(fileToUpload.form)
}).done(function(){
alert("success");
}).fail(function(){
alert("failed");
});
}
If you need to support older browsers, then you'll need to use a hidden
<iframe>
, and change your form's
target
to point to that frame. Alternatively, you could use one of the many available jQuery file upload plugins.
On the server-side, you'll need to remove the parameter from your
UploadImages
method, and read the file from
HttpContext.Current.Request.Files
instead.