1.安装ASP.NET Ajax1.0 点击安装

2.在Web项目中添加引用:System.Web.Extensions(Version:1.0.61025.0)

3.更改web.config,在<system.web>节点加入子节点:

    <httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</httpModules>

4.在相关的aspx.cs加入以下代码,注意是static方法

        [WebMethod]
public static string AjaxTest(string str)
{
return "Hello " + str;
}

5.JQuery调用:

    <script type="text/javascript">
function ajaxTest(str) {
$.ajax({
url: "/Default.aspx/AjaxTest",
type: "post",
dataType: "json",
contentType: "application/json",
data: "{'str':'" + str + "'}",
success: function(data) {
alert(data);
},
error: function(x, e) {
alert(x.responseText);
//alert("失败!!");
}
});
}
</script>

相关文章:

  • 2022-12-23
  • 2021-06-06
  • 2021-12-04
  • 2021-11-27
  • 2021-11-09
  • 2022-12-23
  • 2021-07-24
  • 2021-07-29
猜你喜欢
  • 2021-09-20
  • 2021-08-05
  • 2021-12-18
  • 2022-12-23
  • 2021-06-19
  • 2021-11-23
相关资源
相似解决方案