David Shochet David Shochet - 4 months ago 10
Ajax Question

Accessing PageMethod from aspx page

I have a webforms application and need to make an jquery ajax call to a PageMethod (i.e. WebMethod) in code behind from my aspx page. So far it does not work for me. Is this possible?
Here is my code:

$(function()
{
setInterval(function(){
$.ajax({
type: "GET",
url: "/ClientBillingBillDetails.aspx/MyPageMethod",
data: {someData: '<%= TheData %>'},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(result) {

}
});
}, 10000);
});

[System.Web.Services.WebMethod]
public static string MyPageMethod(int someData)
{
return "";
}


Is something wrong with my URL or something else?

Thanks

Answer

Try This:

$(function () {
            setInterval(function () {
                $.ajax({
                    type: "POST",
                    url: "/ClientBillingBillDetails.aspx/MyPageMethod",
                    data: "{ 'someData': '<%= TheData %>' }",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {

                }
            });
        }, 10000);
        });
Comments