well, i want to load the page that was indicated in the first parameter but not sure what to place in the third
#page1.html
<html>
<head>
<script type="text/javascript" src="jquery-1.6.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#btnSubmit").click(function(){
$.ajaxSetup ({
cache: false
});
$.post("test.php", { name: "John"}, what_am_i_placing_here );
});
});
</script>
</head>
<body>
<input type="button" id="btnSubmit" value="submit">
</body>
#test.php
<?PHP
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = $_POST['name'];
print "hello" . $name;
}
?>
and please can you give me reading links about what kind of values can i place at the third parameter? i only know this.
http://api.jquery.com/jQuery.post/
but the third is so vast im not sure what to search in the web, some people use it to confirm if the post/get was succe开发者_Go百科ssful, others use it to get some scripts. other use it for callbacks, im not sure, if it can be used to load another page. replies are appreciated.
The value of the third parameter is a function reference to be called when your data is returned. In your case, you could do something like:
$.post("test.php", { name: "John"}, function(pageData){
$('body').html(pageData);
});
If you wanted to stick the contents of the returned page into the page body tag.
Alternatively, you could create a function and pass that function in. So,
function handlePageData(pageData){
...
do stuff with page data in javascript
...
}
...
$.post("test.php", { name: "John"}, handlePageData);
you can put the callback there.
$.post("test.php",
{ name: "John"},
function(data){
alert(data);
}
);
this will alert hello John
精彩评论