所以我試圖在我的 Sharepoint 2013 Visual WebPart 中做 jQuery ajax 的基本示例:<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script><script type = "text/javascript">function ShowCurrentTime() { $.ajax({ type: "POST", url: "SPtest.aspx/GetCurrentTime", data: '{name: "' + $("#<%=txtUserName.ClientID%>")[0].value + '" }', contentType: "application/json; charset=utf-8", dataType: "json", success: OnSuccess, failure: function(response) { alert(response.d); } });}function OnSuccess(response) { alert(response.d);}</script><div>Your Name :<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><input id="btnGetTime" type="button" value="Show Current Time" onclick = "ShowCurrentTime()" /></div>并在 VisualWebPart1UserControl.ascx.cs 中的服務(wù)器上[System.Web.Services.WebMethod]public static string GetCurrentTime(string name){ return "Hello " + name + Environment.NewLine + "The Current Time is: " + DateTime.Now.ToString();}它不起作用,如果在 chrome 中打開調(diào)試器,我可以看到它在服務(wù)器端拋出這個(gè)錯(cuò)誤 500:Server Error in '/' Application.Unknown web method GetCurrentTime.Parameter name: methodNameDescription: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentException: Unknown web method GetCurrentTime.Parameter name: methodNameSource Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.Stack Trace: 我不知道出了什么問題。
jQuery ajax 在 Sharepoint 可視 Web 部件中不起作用
慕田峪9158850
2021-08-22 18:11:29