【问题标题】:Ajax Call in asp.netasp.net 中的 Ajax 调用
【发布时间】:2013-08-17 13:32:03
【问题描述】:

我在 asp.net 中进行 JQuery Ajax 调用,我正在使用我的 WebMethod 返回字符串,但是在 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

【问题讨论】:

  • 可以发一下webmethod吗?
  • @Xikinho90 我也发布了方法,GetData()

标签: c# asp.net ajax


【解决方案1】:

像这样试试。使用 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'); }
});

【讨论】:

  • 未知网络方法GetData。
    参数名称:methodName
猜你喜欢
  • 2011-12-26
  • 1970-01-01
  • 2012-03-12
  • 2013-05-13
  • 2015-11-26
  • 2011-03-27
  • 2016-12-15
  • 1970-01-01
  • 2013-03-06
相关资源
最近更新 更多