[Ajax]ajax学习与理解
发布时间:2020-12-15 21:58:19 所属栏目:百科 来源:网络整理
导读:1.新建demo.aspx页面。 2.首先在该页面的后台文件demos.aspx.cs中添加引用。 using System.Web.Services; 3.无参数的方法调用. 大家注意了,这个版本不能低于.net framework 2.0。2.0已下不支持的。 后台代码: [WebMethod] public static string SayHello()
1.新建demo.aspx页面。 using System.Web.Services;
3.无参数的方法调用.
大家注意了,这个版本不能低于.net framework 2.0。2.0已下不支持的。 [WebMethod] JS代码:
$(function() { 页面代码:
<form id=form1" runat=server"> 运行效果如下:
3.有参数方法调用 string GetStr(string str,string str2)
{ return str + str2; } JS代码: ").click(function() { $.ajax({ type: url: demo.aspx/GetStr方法传参的写法一定要对,str为形参的名字,str2为第二个形参的名字 data: {'str':'我是','str2':'XXX'} alert(data.d); },255); line-height:1.5!important">false; }); }); JS代码: demo.aspx/GetArray插入前先清空ul $(#list").html(""); 递归获取数据 $(data.d).each(function() { 插入结果到li里面 $(").append(<li>" + this + </li>"); }); alert(data.d); },255); line-height:1.5!important">false; }); }); |