Currently, I am working with JavaScript and C# in aspnet. My goal is to pass 3 values from the Asp Page to the code behind, using the Json method. Below is how I achieve this:
//initialize x, y and nome
var requestParameter = { 'xx': x, 'yy': y, 'name': nome };
$.ajax({
type: 'POST',
url: 'Canvas.aspx/GetData',
data: requestParameter,
//contentType: "plain/text",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (data) {
alert(data.x);
},
error: function () { alert("error"); }
});
On the C# side of things, the code looks like this:
[WebMethod]
public static string GetData(Object[] output)
{
return output.ToString();
}
I am facing an issue where I keep receiving an alert saying "error" (the one that I defined in the ajax post method). I would appreciate any insights on why this might be happening and tips on how to prevent it. Thank you in advance.