beforeSend: When we send a request to the server then before that the beforeSend function will excute.
- <script type="text/javascript" language="javascript">
-
- $("#btn").live("click",function(){
- var fname = $("#fname").val();
- var lname = $("#lname").val();
- $.ajax({
- type:"POST",
- url:"demo.php",
- data:"fname="+fname+'&lname='+lname,
- beforeSend: function(data){
- alert("this test");
- }
- });
- });
-
- </script>
Complete: If the request successfully executed when the request finishes.
- <script type="text/javascript" language="javascript">
-
- $("#btn").live("click",function(){
- var fname = $("#fname").val();
- var lname = $("#lname").val();
- $.ajax({
- type:"POST",
- url:"demo.php",
- data:"fname="+fname+'&lname='+lname,
- complete:function(data){
- alert(data);
- }
- });
- });
-
- </script>
Data: Which data (string) value will be sent to the server.
- <script type="text/javascript" language="javascript">
-
- $("#btn").live("click",function(){
- var fname = $("#fname").val();
- var lname = $("#lname").val();
- $.ajax({
- type:"POST",
- url:"demo.php",
- data:"fname="+fname+'&lname='+lname,
- });
- });
-
- </script>
Success: When this function is executed if the request succeeds.
- <script type="text/javascript" language="javascript">
-
- $("#btn").live("click",function(){
- var fname = $("#fname").val();
- var lname = $("#lname").val();
- $.ajax({
- type:"POST",
- url:"demo.php",
- data:"fname="+fname+'&lname='+lname,
- success:function(data){
- alert(data);
- }
- });
- });
-
- </script>
type This is used to send data to a GET or POST method. The default value is GET.
POST method
- <script type="text/javascript" language="javascript">
-
- $("#btn").live("click",function(){
- var fname = $("#fname").val();
- var lname = $("#lname").val();
- $.ajax({
- type:"POST",
- url:"demo.php",
- data:"fname="+fname+'&lname='+lname,
- success:function(data){
- alert(data);
- }
- });
- });
-
- </script>
GET method
- <script type="text/javascript" language="javascript">
-
- $("#btn").live("click",function(){
- var fname = $("#fname").val();
- var lname = $("#lname").val();
- $.ajax({
- type:"GET",
- url:"demo.php",
- data:"fname="+fname+'&lname='+lname,
- success:function(data){
- alert(data);
- }
- });
- });
-
- </script>
url: Which the request is sent.
- <script type="text/javascript" language="javascript">
-
- $("#btn").live("click",function(){
- var fname = $("#fname").val();
- var lname = $("#lname").val();
- $.ajax({
- type:"POST",
- url:"demo.php",
- data:"fname="+fname+'&lname='+lname,
- success:function(data){
- alert(data);
- }
- });
- });
-
- </script>