开发者

jQuery + ASP.NET 4.0 ajax page method not working

I have used whole lots of options resolving this, but it is not working.

My breakpoint is not hit in the Web Met开发者_StackOverflow社区hod. Also, the success function is being called, however, entire page content is returned not the string "hello".

My page does not at all use asp.net ajax scriptmanager. It uses plain jQuery only. I am using ASP.NET 4.0.

In brief, my page method is defined as:

[WebMethod]
public static string Populate()
{
    return "hello";
}

The ajax call is:

$.ajax({
    url:'WebForm3.aspx/Populate',
    data:{},
    dataType:"json",
    type:"GET",
    success: function(msg) {
        alert("success");
    },
    error: function(msg, text) {
        alert(text);
    }
});


Page methods only work when POSTed to, like this:

$.ajax({
    url:'WebForm3.aspx/Populate',
    data: '{}',
    dataType:"json",
    type:"POST",
    contentType: 'application/json; charset=utf-8',
    success: function(msg) {
        alert("success");    },
    error: function(msg, text) {
        alert(text);
    } 
 });

Don't forget to quote the data argument: data: '{}'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜