I'm using JavaScript and C# on aspnet. And i want to pass 3 values from the Asp Page to the code behind, and to do so i am using Json method. Here it is how i do:
//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"); }
});
And then on the C# i do:
[WebMethod]
public static string GetData(Object[] output)
{
return output.ToString();
}
For some reason i keep on getting the alert saying "error" (the one that i defined on the ajax post method). I would like to know why, and how can i avoid that. Thanks in advance