一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

jquery AJAX $.post $.get用法

时间:2010-08-23 编辑:简简单单 来源:一聚教程网

jquery代码ajax

jquery.post("newdoajax.asp教程x", { max: ' n !', name: 'wsenmin' }, function(data) { alert(data) });
jquery.get("newdoajax.aspx", { max: ' b !', name: 'wsenmin' }, function(data) { alert(data) });
var superman = "max=i am jq &name= it is ajax ";
jquery.ajax({
type: "post",
url: "newdoajax.aspx",
data: superman,
success: function(msg) {alert(msg);}
});

asp.net教程

<%@ page language="c#" validaterequest="false" enablesessionstate="true"%>
<%@ import namespace="system.data.sqlclient" %>
<%@ import namespace="system.data" %>
<%@ import namespace="system.configuration"%>
<%@ import namespace="system.web.security"%>
<%@ import namespace="system.drawing"%>

 

$.ajax()这个是jquery 的底层 ajax 实现。简单易用的高层实现见 $.get, $.post 等。

这里有几个ajax事件参数:beforesend ,success ,complete ,error 。我们可以定义这些事件来很好的处理我们的每一次的ajax请求。

$.ajax({url: 'stat.php教程',

type: 'post',

data:{name:"keyun"},

datatype: 'html',

timeout: 1000,

error: function(){alert('error loading php document');},

success: function(result){alert(result);}

});

asp.aspx页面代码

response.contenttype = "application/网页特效on";response.write("{result: '" + request["name"] + ",你好!(这消息来自服务器)'}");jquery 代码:
$.post("ajax.aspx", { action: "post", name: "lulu" }, function (data, textstatus){ // data 可以是 xmldoc, jsonobj, html, text, 等等. //this; // 这个ajax请求的选项配置信息,请参考jquery.get()说到的this alert(data.result); }, "json");

 

jquery.post( url, [data], [callback], [type] ) :使用post方式来进行异步请求
参数:
url (string) : 发送请求的url地址.
data (map) : (可选) 要发送给服务器的数据,以 key/value 的键值对形式表示。
callback (function) : (可选) 载入成功时回调函数(只有当response的返回状态是success才是调用该方法)。
type (string) : (可选)官方的说明是:type of data to be sent。其实应该为客户端请求的类型(json,xml,等等)
这是一个简单的 post 请求功能以取代复杂 $.ajax 。请求成功时可调用回调函数。如果需要在出错时执行函数

热门栏目