[英]asp.net jquery ajax post
我試圖從模式對話框窗口上單擊按鈕,使用jquery / ajax調用asp.net方法。 但是我似乎得到的只是警惕地說“錯誤”。 我在網上看到了許多類似的示例,但似乎無法正常工作。 我正在調用的頁面/方法(newcall.aspx / savenote)與所有jquery / ajax等位於同一頁面。
有任何想法嗎?
謝謝,
var dlg = jQuery("#dialog2").dialog({
bgiframe: false,
autoOpen: true,
height: 410,
width: 800,
modal: true,
show: 'Transfer',
hide: 'Transfer',
draggable: true,
resizable: true,
buttons: {
"Cancel": function() {
$(this).dialog("close");
},
"Save": function() {
var txtnote = document.getElementById("<%=txtNote.ClientID %>").value;
$.ajax({
type: "POST",
url: "newcall.aspx/savenote",
data: txtnote,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
}
});
$(this).dialog("close");
}
}
}
);
方法后面的代碼:(此刻,我只是返回“確定”)
Public Function savenote() As String
Return "ok"
End Function
您需要添加WebMethod屬性,將頁面方法聲明為Shared
,然后將要發送的數據與該方法的簽名進行匹配。 這是更改服務器端方法的方法:
<WebMethod()>_
Public Shared Function savenote() As String
Return "ok"
End Function
您可能不更改數據參數就可以擺脫困境,但可能不會,因為它是無效的JSON。 暫時嘗試將數據參數更改為{}
。 當您准備開始將txtnote傳遞到服務器端方法時,您需要將其傳遞為{txtnote: 'Your note string here'}
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.