簡體   English   中英

在asp.net中調用Ajax

[英]Ajax Call in asp.net

我在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
}

我在MyPage.aspx中稱這個Ajax

這樣嘗試。 使用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