I have the following page method in the file default.aspx.vb, using .NET 2.0:
<WebMethod()> _
Public Shared Function GetStatisticData(ByVal userId As Integer) As JavaScriptSerializer
Dim stats As JavaScriptSerializer = New JavaScriptSerializer()
stats.Serialize(statBiz.GetAllSaleStatistics(userId))
Return stats
End Function
And in default.aspx
opt.ajax({
type: "POST",
url: 'default.aspx/GetStatisticData',
data: "{userId: 6601}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
console.log(data);
},
error: function (request, status, error, response) {
console.log(error);
}
});
But the method in the codebehind file does never get hit and i get this error from the console log:
SyntaxError: Unexpected token < in JSON at position 2
at JSON.parse (<anonymous>)
at n.parseJSON (jquery-1.12.4.min.js:11)
at Xb (jquery-1.12.4.min.js:11)
at y (jquery-1.12.4.min.js:11)
at XMLHttpRequest.c (jquery-1.12.4.min.js:11)
Can somebody tell me what I am missing here?