I am trying to Send Image using Ajax Call and transfer code behind web method asp.net c#.
Below is my script.
<script type="text/javascript">
function SubmitFunction() {
alert(imgData_Based64String);
imgData_Based64String = "test";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "index.aspx/SaveImage",
data: "{ 'Based64BinaryString' :'" + imgData_Based64String + "'}",
dataType: "json",
success: function (data) {
alert("success");
},
error: function (result) {
alert("Error");
}
});
}
</script>
Below is my image and button code.
<img src="img.jpg" id="img" width="100px" height="100" />
<asp:Button ID="btnCapture" Text="Capture" runat="server" OnClientClick="SubmitFunction();"
OnClick="btnCapture_Click" />
Code behind C#.
[System.Web.Services.WebMethod]
public static void SaveImage(string Based64BinaryString)
{
string Value = Based64BinaryString;
}
Actually I am new into to Ajax call, Image should convert to binary format and transfer to web method string value. Also Image ID is not declaring into the above script code to convert binary format. What I am trying one image is there and that Image to transfer to a SQL table.