

语法结构:
$.get(url, [data], [callback], [type]);
参数解析:
1.URL:必须,规定请求的URL。
2.data:可选,待发送 Key/value 参数。
3.callback:可选,请求成功后所执行的回调函数。
4.type:可选,返回内容格式,xml, html, script, json, text, _default。
代码实例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.gxlcms.com/" />
<title>php.cn</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#bt").click(function(){
$.get("mytest/demo/antzone.txt",function(data,status){
alert("Data:"+data+"\nStatus:"+status);
})
})
})
</script>
</head>
<body>
<input type="button" value="查看效果" id="bt"/>
</body>
</html>2. $.post() 方法通过HTTP POST请求从服务器上请求数据。
语法结构:
$.post(URL,data,callback);
参数解析:
1.URL:必须,规定请求的URL。
2.data:可选,规定连同请求发送的数据。
3.callback:可选,规定请求成功后所执行的函数名。
代码实例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.gxlcms.com/" />
<title>php.cn</title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#bt").click(function(){
$.post("mytest/demo/antzone.html",function(data,status){
alert("Data:"+data+"\nStatus:"+status);
})
})
})
</script>
</head>
<body>
<input type="button" value="查看效果" id="bt"/>
</body>
</html>这是一个简单的 POST 请求功能以取代复杂 $.ajax ,请求成功时可调用回调函数。如果需要在出错时执行函数,请使用 $.ajax。
$.post(
'http://www.gxlcms.com/ajax.php',
{Action:"post",Name:"lulu"},
function(data,textStatus){
//data可以是xmlDoc,jsonObj,html,text,等等.
//this;//这个Ajax请求的选项配置信息,请参考jQuery.get()说到的this
alert(data.result);
},
"json"//这里设置了请求的返回格式为"json"
);如果你设置了请求的格式为"json",此时你没有设置Response回来的ContentType 为:Response.ContentType = "application/json"; 那么你将无法捕捉到返回的数据。
注意,上面的示例中 alert(data.result); 由于设置了Accept报头为"json",这里返回的data就是一个对象,因此不需要用eval()来转换为对象。
