I am able to make it work (success callback).
But what i get in response is the whole HTML of default.aspx
The AJAX:
function CreateLottery(lottery) {
debugger; // 'lottery' comes with the properties of the Lottery class
$.ajax({
type: 'POST',
url: 'default.aspx/Create',
data: JSON.stringify({ data: lottery }),
dataType: 'text',
success: function (data, status) {
alert(data.TotalValue + " " + status) //"undefined success"
},
error: function () {
alert("error!")
}
});
}
I get "undefined success" in the alert. "data" is the whole html document, not a "Lottery" object.
The Create WebMethod and the Lottery class:
[WebMethod]
public static Lottery Create(Lottery lottery)
{
return lottery;
}
public class Lottery
{
public string TotalValue { get; set; }
public string Players { get; set; }
}
I can't figure out what is going on, the WebMethod is returning exactly the same object that it received, how i can't access it on the success callback?
EDIT: The WebMethod is not being hit. The "ScriptManager" is present in default.aspx with EnablePageMethods set to true. If i change the WebMethod name (Create) to anything and keep /Create in AJAX url still get the whole default.aspx HTML in response.