今天我们来学习jQuery的$.post()函数。相对于$.ajax()函数来说,$.post()函数更加简单和方便,但是只能通过POST的方式将数据参数提交到你需要虚拟访问的php文件。
我们先来看一下$.post()函数内的参数:
$.post(url,data,callback,type)
url---待载入页面的 URL 地址。
data---待发送 Key / value 参数。
callback---载入成功时回调函数。
type---返回内容格式,xml, html, script, json, text, _default。
下面举一个实际例子:
===============================================================
ajax.html
<html>
<head>
<title>$.ajax的应用</title>
<script type="text/javascript" language="javascript" src="./js/jquery.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function(){
$('#bot_1').click(function(){
$.post('ajax.php',{web:"mysql100"},function(data,st){$("div").html(data);})
})
})
</script>
</head>
<center><h2>$.ajax的应用</h2></center>
<center><div>这是需要显示的地方</div></center>
<center><button id="bot_1">点击我吧</button></center>
</html>
===============================================================
ajax.php
<?php
echo '您要访问的网站是'.$_POST['web'];
?>
以上就是jquery如何实现ajax技术2:$.post()的内容,更多相关内容请关注龙方网络(www.yzlfxy.com)!