jQuery对Ajax操作进行了封装。
最底层的方法:$.ajax()
第二层方法 :$.load() , $.get() , $.post()
第三次方法:$.getScript() , $.getJSON()
Load()方法 ,通常用来从web服务器上获取静态的数据文件
Load()结构: load(url [,data] [,callback])
url: 类型 string ,请求HTML页面的URL地址
data: 类型Object ,发送至服务器的key or value数据
callback: 类型Function ,请求完成时的回调函数,无论请求成功或失败
例子Look
ajax.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajax2.aspx.cs" Inherits="ajax_ajax2" %>
Untitled Page
test.html
Untitled Page
comments:
zheng:
soft
Lee:
chair
King
floor
$.get() & $.post()
$.get() & $.post()是jQuery中的全局函数
$.get()方法
url:类型String ,请求的HTML页面的URL地址
data:类型Object ,发送到服务器的key或value,数据会作为Querystring附加到请求的URL中。
callback:类型Function , 载入成功是回调函数(只有当Response的返回状态是success才调用该方法,这和load不一样),自动将请求结果和状态传递给该方法。
get的回调函数只有2个参数
function(data,textstatus){
data :返回的内容,比如html片段,xml文档
textstatus:请求状态:success error timeout notmodified 4中
}
type:类型String,服务器返回内容的格式,比如xml,html,text,json等
Untitled Page
已有评论:
test2.aspx
Untitled Page
test2.aspx.cs
public partial class ajax_test2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request.QueryString["username"].ToString();
string content = Request.QueryString["content"].ToString();
lbl.Text= ""+username+"
"+content+"
";
}
}
test2.aspx.cs
public partial class ajax_test2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string username = Request["username"].ToString();
string content = Request["content"].ToString();
lbl.Text = "" + username + "
" + content + "
";
}
}