Ajax Syntax
---------------------------------------- ajax.php------------------------------------------------------------
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<a href="javascript:void(0)" onclick="click_here()"> click Here </a>
<script>
function click_here(){
//alert('ajax');
jQuery.ajax({
url:'get.php',
type:'post',
success:function(result){
alert(result);
}
});
}
</script>
<hr>
<input type="textbox" id="num1">
<script>
function click_here(){
var num1 = jQuery("#num1").val();
jQuery.ajax({
url:'get.php',
type:'post',
data:'num1='+num1,
success:function(result){
alert(result);
} });
}
</script>
---------------------------get.php-------------------------
<?php
//echo"Hello";
// print_r($_POST);
echo $_POST["num1"]+20;
?>
-----------------------------------types_ajax.php---------------------------
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<a href="javascript:void(0)" onclick="click_here()"> click Here </a>
<script>
hit1();
hit2();
function hit1(){
jQuery.ajax({
url:'get1.php',
type:'post',
async:false,
success:function(result){
//alert(result);
console.log(result);
}
});
}
function hit2(){
jQuery.ajax({
url:'get2.php',
type:'post',
success:function(result){
// alert(result);
console.log(result);
} });
}
</script>
-----------------------------get1.php-----------------------
<?php
sleep(5);
echo"get1";
?>
------------------------------------get2.php---------------------------
<?php
echo"get2";
?>
===================================================================
No comments:
Post a Comment