Jquery ajax不能在asp.net中工作

本文关键字:net 工作 asp ajax 不能 Jquery | 更新日期: 2023-09-27 18:03:02

我在一个asp.net webform项目的中间。我想使用jquery ajax。下面是我的代码:

     <asp:Button ID="btn_comment" runat="server" CssClass="contact_btn pull-right" Text="send" OnClientClick="callajax(event)" />

ajax:

<script type="text/javascript">
        function callajax(e) {
            e.preventDefault();
            $.ajax({
            type: "POST",
            url: "../Music.aspx/sendcomment",
            data: '{name: "' + $("#<%=TextBox1.ClientID%>").text() + '" , email:"' + $("#<%=TextBox2.ClientID%>").text() + '" , website: "' + $("#<%=TextBox4.ClientID%>").text() + '" , comment: "' + $("#<%=TextBox3.ClientID%>").text() + '" }',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                if (response.d) {
                    alert('ok');
                }
            },
            failure: function (response) {
                alert('eror');
            }
        });
        }
</script>
sendcomment method:
    [WebMethod]
    public static void sendcomment(string name , string email , string website , string comment)
        {
          // do something
        }
        catch (Exception)
        {
        }
    }

我还将jquery文件添加到我的项目中,但是当我运行项目并单击按钮时,它不起作用并触发sendcomment方法。我也使用updatepanel,但它不起作用。有人能帮我吗?

Jquery ajax不能在asp.net中工作

使用这个作为url

url: "Music.aspx/sendcomment",