积极答复者
PageMethods调用页面方法返回的是整个html??

问题
-
using System;
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default3 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[System.Web.Services.WebMethod]
public static string Hello(string yourName)
{
return string.Format("Hello {0}", yourName);
}
}
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"></asp:ScriptManager>
<input id="Button1" type="button" value="button" />
</div>
</form>
</body>
</html>
<script type="text/javascript">
$addHandler($get("Button1"), "click", clickFun);
function clickFun() {
PageMethods.Hello("五笔拼音", sucFun);
}
function sucFun(r) {
alert(r);
}
</script>
答案
-
你好,
我在我的电脑上测试了你的代码,你的代码没有问题,可以正常显示。
我建议你可以重新打开你的Visual Studio, 如果还是不行,我建议你可以新建一个项目来测一下你的代码。
- 已建议为答案 Zhi LvModerator 2015年11月4日 6:23
- 已标记为答案 Zhi LvModerator 2015年11月9日 6:43
全部回复
-
-
你好,
我在我的电脑上测试了你的代码,你的代码没有问题,可以正常显示。
我建议你可以重新打开你的Visual Studio, 如果还是不行,我建议你可以新建一个项目来测一下你的代码。
- 已建议为答案 Zhi LvModerator 2015年11月4日 6:23
- 已标记为答案 Zhi LvModerator 2015年11月9日 6:43