News
IBM to offer mobile security as a service IBM will start delivering mobile security-as-a-service (MaaS) through its own cloud infrastructure in India, a move that is expected to better address in-country data requirements... IBM Spectrum Computing: IBM has enlarged its portfolio of software-defined infrastructure solutions with cognitive features for workload management.  * LiFi internet technology has been introduced, the new type of wireless internet connection that gives 100 times faster than traditional WiFi -- Invented by Professor Harald Haas from the University of Edinburgh. * Sci. Rachid Yazami has developed a smart chip that charges smartphones in less than 10 minutes. BenQ has launched BlueCore projector - Consumer electronics major BenQ has launched its first BlueCore laser light source projector. For those unaware, devices with BlueCore laser technology have a high contrast output of 80000:1 with an extended lamp life and efficiency. ***
  Jan 3 2015 10:32PM     John
  0 Comments    711 Views  
Ajax stands for Asynchronous JavaScript and XML. Ajax is used to Update the part of the web page without reloading the entire page. In other words, Give request to the server and get response with out page reload.

Working flow of Ajax
XMLHttpRequest :
As we discussed earlier, XMLHttpRequest is the Object and Its used to Update the part of the webpage with out reloading the entire page.
We can use below syntax to create a XMLHttpRequest Object for all browsers except older versions of IE [ IE 5 and IE 6]
Syntax :
var xmlHttp = null;

xmlHttp = new XMLHttpRequest();
For Older verions of IE, Use the following Syntax
Syntax :
var xmlHttp = null;

xmlHttp = new XMLHttpRequest("Microsoft.XMLHTTP");
Code :
Below function Is used to create XMLHttpRequest Object based on browsers.
<script language="javascript" type="text/javascript">
        var xmlHttp;
        function GetXmlHttpObject() {
            var xmlHttp = null;
            try {
                xmlHttp = new XMLHttpRequest();
            }
            catch (e) {
                try {
                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch (e) {
                    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                }
            }
            return xmlHttp;
        }
    </script>
Send Request to the Server :
Before sending Request to the server, should use open method open(). Open() method takes 3 arguments such as
Method - Type Of the Request, It may be “Get” Or “Post”.
Url – Url of the file which you are going to call.
Asynchronous – Its takes boolean value “True” Or “False”.
Syntax :
xmlHttp.open("POST", url, true);
For method “POST” Type we need to specify string or null to the send() method.
xmlHttp.send(null);
xmlHttp.open("GET", url, true);
For method “GET” Type, No need to specify string to the send() method.
xmlHttp.send();
Code :
var url = 'AjaxCall-Javascript.aspx?Parameter1=1';
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) {
alert(xmlHttp.responseText);
}
if (xmlHttp.readyState == 4) {
// LoadingPage();
}
}
}
xmlHttp.open("POST", url, true);
xmlHttp.send(null);
Server Response to the browser :
We can get response from the server as responseText – response data as string and responseXml – response data as Xml.
The below onreadystatechange function will call automatically when readyState value changes.
Code :
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
if (xmlHttp.status == 200) { // Status 200: "OK"
alert(xmlHttp.responseText);
}
if (xmlHttp.status == 200) { // Status 404: "Page Not Found"
alert(xmlHttp.responseText);
}
if (xmlHttp.readyState == 4) {
// LoadingPage();
}
}
}
ReadyState store the status of XMLHttpRequest and it has following values
0: request not initialized
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
Hi, This is John.I hope this page will helps you to understand the concept of Send Request and Server Response in JavaScript Ajax.Thanks.
BackToTop
Comments



 
Search
1&1 Hosting
Recent Posts
Bind Gridview from CSV file in Asp.Net C#
Jun 18 2016 11:38PM Posted By Michael
Call WebService method from jQuery in every 1 minute
Feb 27 2016 11:51AM Posted By John
Gridview custom CSS in ASP.Net
Feb 25 2016 10:59AM Posted By Micheal Ryan
Read excel file and bind to Gridview in C#
Feb 25 2016 10:20AM Posted By Micheal
Read excel file and convert to List in C#
Feb 25 2016 6:26AM Posted By Michael
Encryption and Decryption for Password in C#
Feb 17 2016 3:52AM Posted By Michael
How to create Chart in ASP.Net C#
Feb 16 2016 8:03AM Posted By Michael Ryan
Tags
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: