[英]jquery ajax does not work in asp.net
我在一個asp.net網絡表單項目的中間。 我想使用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方法:
[WebMethod]
public static void sendcomment(string name , string email , string website , string comment)
{
// do something
}
catch (Exception)
{
}
}
我也將jquery文件添加到我的項目中,但是當我運行該項目並單擊按鈕時,它不起作用並觸發sendcomment方法。 我也使用updatepanel但它不起作用。有人可以幫我嗎?
將此用作網址
url: "Music.aspx/sendcomment",
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.