post()方法jQuery.post(url,[data],[callback],[type])方法使用POST HTTP请求从服务器加载页面。
假设我们在result.php文件中包含以下PHP内容,
以下是显示此方法用法的代码片段-
<head>
<script src = "https://cdn.staticfile.org/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#driver").click(function(event){
$.post(
"result.php",
{ name: "Ricky" },
function(data) {
$('#stage').html(data);
}
);
});
});
</script>
</head>
<body>
<p>Click on the button to load result.html file −</p>
<div id = "stage" style = "background-color:cc0;">
STAGE
</div>
<input type = "button" id = "driver" value = "Load Data" />
</body>get()方法jQuery.get(url,[data],[callback],[type])方法使用GET HTTP请求从服务器加载数据。
假设我们在 result.php文件中包含以下PHP内容-
<?php
if( $_REQUEST["name"] ) {
$name = $_REQUEST['name'];
echo "Welcome ". $name;
}
?>以下是显示此方法用法的代码片段-
<head>
<script src = "https://cdn.staticfile.org/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#driver").click(function(event){
$.get(
"result.php",
{ name: "John" },
function(data) {
$('#stage').html(data);
}
);
});
});
</script>
</head>
<body>
<p>Click on the button to load result.html file</p>
<span id = "stage" style = "background-color:#cc0;">
STAGE
</span>
<div><input type = "button" id = "driver"
value = "Load Data" /></div>
</body>