我正在使用 bootstrap/jquery 3.4.1 js 開發 ASP.NET Web 窗體項目。我遇到了讓我的 AJAX Post 工作的問題。它應該在 Schedule.aspx 中命中我的 [WebMethod],但事實并非如此。我已經在它上面設置了一個斷點,并且在單擊保存按鈕時它從未被激活。AJAX 成功并彈出警報,我已經驗證了 stringify 數據按預期輸出,但為什么它沒有命中 [WebMethod]?這是我的 JavaScript 函數:$(document).on('click', '#modalSave', function (e) { var testValue = "TestValue"; $.ajax({ type: "POST", url: "Schedule.aspx/InsertItem", data: JSON.stringify({ Content: testValue }), contentType: "application/json; charset=utf-8", dataType: "json", success: function () { alert("AJAX success"); $('#DetailsModal').modal('hide'); } })});我的 [WebMethod]using System.Web.Services;namespace Scheduler{ public partial class Schedule : Page { [WebMethod] public static string InsertItem(string Content) { return Content; } }}我的模式和保存按鈕:<div id="DetailsModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">× </button> <h4 class="modal-title" id="myModalLabel">Modal title</h4> </div> <div class="modal-body"> <textarea id="modalTextArea" style="width: 100%; height: 300px;"></textarea> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button id="modalSave" type="button" class="btn btn-primary">Save changes</button> </div> </div> </div></div>
AJAX Post 未調用 ASP.NET Web 窗體 [WebMethod]
茅侃侃
2023-05-18 10:46:53