jQuery with ajax

By ukmodak | April 29th 2021 06:09:07 AM | viewed 214 times

jQuery - AJAX Introduction

AJAX is the art of exchanging data with a server, and updating parts of a web page - without reloading the whole page.

The folowing are different type method:

ajax method

  1. $.load()- method loads data from a server and puts the returned data into the selected element
  2. $.get()- method requests data from the server with an HTTP GET request.
  3. $.post()-method requests data from the server using an HTTP POST request.

Example

$("button").click(function(){
  $("#div1").load("demo_test.txt", function(responseTxt, statusTxt, xhr){
    if(statusTxt == "success")
      alert("External content loaded successfully!");
    if(statusTxt == "error")
      alert("Error: " + xhr.status + ": " + xhr.statusText);
  });
}); 


$("button").click(function(){
  $.get("demo_test.asp", function(data, status){
    alert("Data: " + data + "\nStatus: " + status);
  });
}); 


$("button").click(function(){
  $.post("demo_test_post.asp",
  {
    name: "Donald Duck",
    city: "Duckburg"
  },
  function(data, status){
    alert("Data: " + data + "\nStatus: " + status);
  });
}); 
bONEandALL