javascript - How do I send texbox and attachement to webmethod using jquery ajax call? -


i trying send textbox , input file data webmethod. have been googling quite sometime still not sure how can achieve this:

jquery/ajax call:

 var datatosend = new formdata();             datatosend.append('file',  document.getelementbyid("myfile").value);  datatosend.append('text',  document.getelementbyid("biddername").value);              $.ajax({                 type: "post",                 url: "suppliermaster.aspx/registersupplier",                 data: datatosend,                 processdata: false,                 contenttype: false,                 datatype: false,                 async: true,                 success: function (data, status) {                     console.log("callwm");                     alert(data.d);                 },                 failure: function (data) {                     alert(data.d);                 },                 error: function (data) {                     alert(data.d);                 }             });          } 

webmethod:

 [webmethod]     public static string registersupplier(httppostedfile file, string biddername)     {          return "a";     } 

it seems unable invoke webmethod.

edit1(as suggested kashif):

 $.ajax({                 type: "post",                 url: "suppliermaster.aspx/registersupplier",                 data: "{'file' : " + document.getelementbyid("myfile").value + ",'biddername':" + document.getelementbyid("txtsuppliername").value + "}",                 async: true,                 contenttype: "application/json; charset=utf-8",                 success: function (data, status) {                     console.log("callwm");                     alert(data.d);                 },                 failure: function (data) {                     alert(data.d);                 },                 error: function (data) {                     alert(data.d);                 }             });   [system.web.services.webmethod]     [system.web.script.services.scriptmethod]      public static string registersupplier(httppostedfile file, string biddername)     {          return "a";     } 

*

you can't ajax post content of file. have post form file. should search how post form file input web method.


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -