post() 方法经过 HTTP POST 请求从服务器载入数据。 javascript
语法: php
$.post(url,data,success(data, textStatus, jqXHR),dataType)
get() 方法经过远程 HTTP GET 请求载入信息 html
$.get(url,data,success(response,status,xhr),dataType)
POST和GET方式差很少,下面只举get的例子。pos就只须要把get化成post
java
1、经过get方式请求加载 jquery
index.html ajax
<html> <head> <title>TODO supply a title</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width"> <script type="text/javascript" src="js/jquery-1.7.2.js"></script> </head> <body> <a href="#" id="getData">获取</a> <div id="content">这里显示ajax请求内容</div> </body> </html> <script> $("doucument").ready(function(){ $("#getData").click(function(){ $.get("ajax.php",{name:"lgx",sex:"boy"},function(result){ $("#content").html(result); }); }); }); </script>
ajax.php 服务器
<?php $name = $_GET['name']; $sex = $_GET['sex']; echo "your name is ".$name .'and sex is '.$sex;
//注意服务端要输出数据,客户端才能接收到。不可以用return哦 post