Tuesday, 14 June 2016

Easy Learn AJAX- Beginners AJAX Tutorials Part 3- Create XMLHttpRequest Object

Hi Friends

In this section will see 


  • Why Create XMLHttpRequest Object?
  • How to Create XMLHttpRequest Object?
  • Examples XMLHttpRequest Object


Why  XMLHttpRequest Object?


  • The XMLHttpRequest Object is used to to Exchange data with Server. this meas that is possible to update part of webpage without reloading the whole webpage.
  •  
  • All modern Browsers supports XMLHttpRequest Object because all moders browsers have built in this object.

  • If older browesr like IE below version we can create ActiveX Object


Basic Syntax for creating XMLHttpRequest Object and ActiveX Object

Variable_name(object_name)= new HttpRequest();     This is Modern Browser

Varibale_name(object_name)= new ActiveXObject("Microsift.XMLHTTP")    This is Older Browser

How to Create XMLHttpRequest Object and ActiveX Object in one way

<head>
<script>
function myfunction()
{
    var xhttp;
      if (window.XMLHttpRequest) 

      {
      xhttp = new XMLHttpRequest();   // Modern browser
      } 

      else
      {
      xhttp = new ActiveXObject("Microsoft.XMLHTTP");  // Older browser 
      }

}
</script>
</head>

How to Check your browser Modern/Older Browser

<html>
<title>XMLHttpRequest Object</title>
<script>
function myfunction()
{
    var xhttp;
      if (window.XMLHttpRequest) 

      {
      xhttp = new XMLHttpRequest();   // Modern browser

              alert("You have Modern Browser!")
      } 

      else
      {
      xhttp = new ActiveXObject("Microsoft.XMLHTTP");  // Older browser

      alert("You have Older Browser!") 
      }

}
</script>

</head>

<body>
<input type="submit" name="submit" value="Check Browser" onclick="myfunction()" />
</body>

</html>

This above code 

  • window.XMLHttpRequest supports will show msg in Modern Browser and we create that xhttp object for XMLHttpRequest method.
  • if does not support will show msg older browser and we create xhttp object for ActiveXObject Method.


I hope this section can clear your doubts and how to create and use in your script..

Thank you!


No comments:

Post a Comment

What is AI- Artificial Intelligence - தமிழில்

Artificial Intelligence : Artificial intelligence leverages computers and machines to mimic the problem-solving and decision-making capabili...