Enter Keyword Hear for Search This Blog

Tuesday, 11 October 2016

what is ajax?how to create ajax with php code

Ajax Introduction

એજેક્સ નો ઉપીયોગ કરી ને તમે પેજ લોડ કાર્ય વિના બધી માહિતી મેળવી શકો.એજેક્સ થી તમે કોઈ પણ ડેટા ઝડપ થી મેળવી શકો છો

- अजाक्स का उपियोग करके आप कोई भी डाटा स्पीड में ले सकते हे और इसकी प्रोसेस प्रोसेसबार में नहीं दिखती अजाक्स अपने डाटा सर्वर को सेंड करते समय सेकुएंस मेन्टेन नहीं करता इस लिए हम डाटा फ़ास्ट एक्सेस कर सकते हे

- Ajax stands for Asynchronous JavaScript and XML. Ajax isn’t a technology; it mixes well-known programming techniques in an uncommon way to enable web developers to build Internet applications with much more appealing user interfaces.

The parts of an Ajax application that happen "under the hood" of the browser, such as sending server queries and dealing with the returned data, are written in JavaScript, and XML is a means of coding and transferring formatted information used by Ajax to efficiently transfer data between server and client.

-  You cannot make use of the XMLHTTPRequest until you have created an instance of it.

-Microsoft first introduced the XMLHTTPRequest object, implementing it in Internet Explorer 5 as an ActiveX object. 


- The following line creates an XMLHTTPRequest object called request

               var request = new XMLHTTPRequest(); 
-  Here we have declared a variable request and assigned to it the value returned from the statement
new XMLHTTPRequest(),which is invoking the constructor method for the XMLHTTPRequest object.
-  To achieve the equivalent result in Microsoft Internet Explorer, you need to create an ActiveX object.
 Here's an example
               var request = new ActiveXObject("Microsoft.XMLHTTP");
- This assigns the name request to the new object.
-  Some versions of Internet Explorer have a different version of MSXML, the Microsoft XML parser, 
installed in those cases you need to use the following instruction
               var request = new ActiveXObject("Msxml2.XMLHTTP");
- For cross Browser detection, this is the following code :

function ajaxFunction()
{
    var xmlhttp;
    if (window.XMLHttpRequest)
    {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    else
    {
      alert("Your browser does not support XMLHTTP!");
    }
}

In above example create a variable named xmlhttp to hold the XMLHttpRequest object,
Try to create the XMLHttpRequest object with xmlhttp=new XMLHttpRequest(). If that fails, 
try xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"). 
This is for IE6 and IE5. If that fails too, the user has a very outdated browser, 
and will get an alert stating that the browser doesn't support XMLHTTP.

Note: The code above can be used every time you need to create an XMLHttpRequest object.
-  XMLHTTPRequest class is predefined in php
-  Ajax have a some method and properties
Method : open, send
Properties :onreadystatechangereadyState, responseText and status 

Ajax With Html demo.html

ajaxdemo.html

<script type="text/javascript">
var http = false;
if(navigator.appName == "Microsoft Internet Explorer")
{
                        http = new ActiveXObject("Microsoft.XMLHTTP");
} else
{
  http = new XMLHttpRequest();
}
function replace()
{
  http.open("GET", "test.txt", true);
  http.onreadystatechange=function()
 {
    if(http.readyState == 4)
   {
      document.getElementById('changed').innerHTML = http.responseText;
    }
 }
  http.send(null);
}
</script>
<p><a href="javascript:replace()">Replace Text</a></p>

<div id="changed">
            Hello, world!
</div>

test.txt
This is the content of test.txt

No comments:

Featured post

what is ajax?how to create ajax with php code

Ajax Introduction -  એજેક્સ નો ઉપીયોગ કરી ને તમે પેજ લોડ કાર્ય વિના બધી માહિતી મેળવી શકો.એજેક્સ થી તમે કોઈ પણ ડેટા ઝડપ થી મેળવી શકો છો...