Currently, I am facing an issue while attempting to create a signature using client-side javaScript
and then forwarding the result to the back-end (c#
) via ajax. The array I am trying to transmit is of the type uint8clampedarray
, but unfortunately, the SetSignature method in the code behind is not being triggered, even though the Page Load method is working as expected.
Client-side javaScript
var signatureByteArray = signature.getSignatureImage();
SendArrayViaAjax(signatureByteArray);
function getSignatureImage() {
return ctx.getImageData(0, 0, canvas.width, canvas.height).data;
}
function SendArrayViaAjax(signatureArray) {
var sigArray = JSON.stringify(signatureArray);
$.ajax({
type: "POST",
data: { array: sigArray },
dataType: "json",
contentType: "application/json; charset=utf-8",
url: "/Intranet/OHS/SOP/SOPSignOffs.aspx/SetSignature",
success: function (msg) {
alert(msg.d + "success");
},
error: function (response) {
alert("an error has occurred");
}
});
}
Code behind
[WebMethod]
public static string SetSignature(string[] array)
{
var x = array[2];
return "success";
}
My question lies in how I can transmit the array directly as uint8clampedarray
through ajax and how it can be retrieved in c#. Alternatively, is there a more efficient approach?
ctx = canvas.getContext("2d");`
This code snippet depicts how I am obtaining the Canvas
element.
Whilst the signature generation process is functioning properly, the challenge lies in sending it back to C#
.