The jQuery.post( url, [data], [callback], [type] ) technique heaps a page from the server using a GET and POST HTTP request.
The method returns XMLHttpRequest object.
$.post( url, [data], [callback], [type] )
Arguments:
Here is the explanation of all the Arguments used by this method:
• url: A string covering the URL to which the call is sent
• data:: This optional Arguments shows key/value pairs or the return value of the .serialize() function that will be sent to the web server.
• callback:: This optional Arguments shows a function to be performed whenever the data is loaded well.
• type:: This optional Arguments shows a type of data to be reverted to callback function: "xml", "html", "script", "json", "jsonp", or "text".
Example:
Assuming we have following PHP content in result.php file:
<?php
if( $_REQUEST["id"] )
{
$id = $_REQUEST['id'];
echo "ID ". $id;
}
?>
Following is a simple example a simple showing the usage of this method:
<html>
<head>
<title>The jQuery basic Example</title>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#load").click(function(event){
$.post(
"page.php",
{ id: "123" },
function(data) {
$('#rec').html(data);
}
);
});
});
</script>
</head>
<body>
<p>View result:</p>
<div id="rec">
STAGE
</div>
<input type="button" id="load" value="Load value" />
</body>
</html>
The method returns XMLHttpRequest object.
$.post( url, [data], [callback], [type] )
Arguments:
Here is the explanation of all the Arguments used by this method:
• url: A string covering the URL to which the call is sent
• data:: This optional Arguments shows key/value pairs or the return value of the .serialize() function that will be sent to the web server.
• callback:: This optional Arguments shows a function to be performed whenever the data is loaded well.
• type:: This optional Arguments shows a type of data to be reverted to callback function: "xml", "html", "script", "json", "jsonp", or "text".
Example:
Assuming we have following PHP content in result.php file:
<?php
if( $_REQUEST["id"] )
{
$id = $_REQUEST['id'];
echo "ID ". $id;
}
?>
Following is a simple example a simple showing the usage of this method:
<html>
<head>
<title>The jQuery basic Example</title>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#load").click(function(event){
$.post(
"page.php",
{ id: "123" },
function(data) {
$('#rec').html(data);
}
);
});
});
</script>
</head>
<body>
<p>View result:</p>
<div id="rec">
STAGE
</div>
<input type="button" id="load" value="Load value" />
</body>
</html>
No comments:
Post a Comment