加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

如何在asp.net用户控件中使用jQuery ajax?

发布时间:2020-12-15 20:47:51 所属栏目:asp.Net 来源:网络整理
导读:我想在asp.net用户控件中使用ajax, $.ajax({ type: "POST",url: "*TCSection.ascx/InsertTCSection",data: "{id:'" + id + "'}",contentType: "application/json; charset=utf-8",dataType: "json",success: function (msg) { var URL = msg.d; alert(URL);
我想在asp.net用户控件中使用ajax,
$.ajax({
        type: "POST",url: "*TCSection.ascx/InsertTCSection",data: "{id:'" + id + "'}",contentType: "application/json; charset=utf-8",dataType: "json",success: function (msg) {
            var URL = msg.d;
            alert(URL);
        });

.cs代码

[WebMethod]
public static string InsertTCSection(string id)
{
    string result = "deneme";
    return result; 
}

解决方法

您不能通过jquery调用保存在usercontrol中的方法.
因为.ascx控件不代表真实的url.

它们旨在嵌入到某些ASP.NET页面中,因此它们在运行时不存在.
你可能会做的是创建一个单独的服务并将你的方法放在那里.
像webservices.

见this,this和其他许多人

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读