不工作我花了一整天,出現此錯誤掙扎,看了幾乎所有的文章,並想盡提示我發現,但仍然不能使它發揮作用。PageMethods與VS2013 Web應用程序
請注意:裏面的ScriptManager EnablePageMethod = TRUE,方法是公共的和靜態的,並飾以[的WebMethod]
相同編碼時使用新的工作都完善與VS2010和與VS2013空項目,但項目 - > web - > web表格輸出附在這裏供您參考。
這是我的代碼。
代碼背後:
[System.Web.Services.WebMethod]
public static string GetCurrentTime(string name)
{
return "Hello " + name + Environment.NewLine + "The Current Time is: "
+ DateTime.Now.ToString();
}
的JavaScript:
<script type="text/javascript">
function ShowCurrentTime() {
PageMethods.GetCurrentTime(document.getElementById("<%=txtUserName.ClientID%>").value, OnSuccess);
}
function OnSuccess(response, userContext, methodName) {
alert(response);
}
</script>
HTML:
<div>
Your Name :
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<input id="btnGetTime" type="button" value="Show Current Time" onclick="ShowCurrentTime()" />
</div>
您可以粘貼您正在使用的頁面的代碼前端嗎?我的意思是你的網頁的完整標記。 – Sunil