jquery-ajax get()和post()
get( url ):使用GET方式来进行异步请求。
参数: url :类型String(必选)发送请求的URL地址. data (Map):(可选) 要发送给服务器的数据,以 Key/value 的键值对形式表示,会做为QueryString附加到请求URL中。 success(data, textStatus, jqXHR):类型: Function()(可选)当请求成功后、载入成功时回调函数(只有当Response的返回状态是success才执行的回调函数)。 dataType:类型:String(可选)从服务器返回的预期的数据类型。默认:智能猜测(xml, json, script, 或 html)。
$.get("./Ajax.aspx", {Action:"get",Name:"wjy"}, function (data,textStatus){
//返回的 data 可以是 xmlDoc, jsonObj, html, text, 等等.
this; // 在这里this指向的是Ajax请求的选项配置信息
alert(data);
//alert(textStatus);//success---请求状态:success,error等等,当然这里捕捉不到error,因为error的时候根本不会运行该回调函数
//alert(this);
});
post( url, , , ) :使用POST方式来进行异步请求
参数: url (String) : 发送请求的URL地址. data (Map) : (可选) 要发送给服务器的数据,以 Key/value 的键值对形式表示。 callback (Function) : (可选) 载入成功时回调函数(只有当Response的返回状态是success才是调用该方法)。 type (String) : (可选)官方的说明是:Type of data to be sent。其实应该为客户端请求的类型(JSON,XML,等等) Ajax.aspx: Response.ContentType = "application/json"; Response.Write("{result: '" + Request + ",你好!(这消息来自服务器)'}");
$.post("./Ajax.aspx", { Action: "post", Name: "wjy" },
function (data, textStatus){
// data 可以是 xmlDoc, jsonObj, html, text, 等等.
//this; // 这个Ajax请求的选项配置信息,请参考jQuery.get()说到的this
alert(data.result);
}, "json");
http://www.cnblogs.com/qleelulu/archive/2008/04/21/1163021.html