[英]jquery ajax does not work in asp.net
I'm in the middle of an asp.net webform project. 我在一个asp.net网络表单项目的中间。 I want to use jquery ajax. 我想使用jquery ajax。 here is my code: 这是我的代码:
<asp:Button ID="btn_comment" runat="server" CssClass="contact_btn pull-right" Text="send" OnClientClick="callajax(event)" />
ajax function : 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 : sendcomment方法:
[WebMethod]
public static void sendcomment(string name , string email , string website , string comment)
{
// do something
}
catch (Exception)
{
}
}
I also add jquery file to my project but when I run the project and click on button it does not work and fire the sendcomment method. 我也将jquery文件添加到我的项目中,但是当我运行该项目并单击按钮时,它不起作用并触发sendcomment方法。 I also use updatepanel but it doesn't work.Can anyone help me? 我也使用updatepanel但它不起作用。有人可以帮我吗?
将此用作网址
url: "Music.aspx/sendcomment",
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.