简体   繁体   English

在asp.net中调用Ajax

[英]Ajax Call in asp.net

I am making JQuery Ajax call in asp.net, I am returning String with my WebMethod, But on success of ajax call I am getting complete HTML of page in result.I also used type: "get" but no luck, below is my code for ajax call 我在asp.net中进行JQuery Ajax调用,使用WebMethod返回String,但是在ajax调用成功后,我得到的是页面的完整HTML。我还使用了类型:“ get”但没有运气,下面是我Ajax调用代码

$.ajax({
    type: "POST",
    url: "MyPage.aspx/GetData", //url to point your webmethod          
    success: function (Result) {
        if (Result != "")
            alert( Result);
        },
    error: function () { alert('error'); }
});

[System.Web.Services.WebMethod()]
public string GetData()
{
    //getting value from Database and returning
}

I am calling this Ajax in MyPage.aspx 我在MyPage.aspx中称这个Ajax

Try it like this. 这样尝试。 With the contentType: "application/json; charset=utf-8" 使用contentType:“ application / json; charset = utf-8”

$.ajax({
    type: "POST",
    url: "MyPage.aspx/GetData", //url to point your webmethod          
    contentType: "application/json; charset=utf-8",
    success: function (Result) {
        if (Result != "")
            alert( Result);
        },
    error: function () { alert('error'); }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM