Is it possible? I have a web form with specific text fields, etc. And the file upload element. I am trying to send data to webmethod using .ajax() method. It seems to me that in this way it is not possible to send the contents of a file to a web method. I canβt even hit the web method.
script type="text/javascript"> var btn; var span; $(document).ready(function (e) { $('#btnsave').on('click', function (event) { Submit(); event.preventDefault(); }); }) function Submit() { $.ajax({ type: "POST", url: "SupplierMst.aspx/RegisterSupplier", data: "{'file' : " + btoa(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); } }); } </script>
HTML:
<input id="txtsuppliername" type="text" /><br /> <input type="file" id="myFile">
Code behind:
[WebMethod] public static string RegisterSupplier(string file, string biddername) {
I have been trying to find a solution for this in a few hours. Nobody seems to be able to help me. Is this possible with this approach. If not, how to do it? Someone suggested that I should try to imagine a whole form instead of passing individual values.
source share