How to send a file to the server from the client side using ajax without using a handler?

I sent the file to the handler page using ajax.but now I'm trying to send the file to webmethod using ajax.i can can to get the file. I put my sample code below, please give me some idea. This is my javacript code

 <input type="file" id="MsoBill"   class="MsoReqdit upload">

    var Frmdata = new FormData();
    var Files = $("#MsoBill").get(0).files;
    Frmdata.append("test", Files[0])


  $.ajax({
        type: "POST",
        url: 'MyForm.aspx/testAjax',
        data: '{test:' + Frmdata + '}',
       contentType: "application/json; charset=utf-8",
       dataType: "json",
        processData:false,
        success: function (res) { debugger; alert(res); },
        failure: function (result) {
            alert("fail");
        }
    });

My server side code

[WebMethod]
public static int testAjax(Object test)
{

        return 1;
}
+4
source share

All Articles