<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<p><b>XMLHttpRequest (XHR)</b> is an API available to web browser scripting languages such as JavaScript. It is used to send HTTP or HTTPS requests to a web server and load the server response data back into the script. Development versions of all major browsers support URI schemes beyond http: and https:, in particular, blob: URLs are supported.An object of XMLHttpRequest is used for asynchronous communication between client and server.</p>
<p><b>It performs following operations:</b></p>
<ul style="text-align: left;">
<li>Sends data from the client in the background</li>
<li>Receives the data from the server</li>
<li>Updates the webpage without reloading it.</li>
</ul>
<h2><b>Properties of XMLHttpRequest object</b></h2>
<p>The common properties of XMLHttpRequest object are as follows:</p>
<p><b>onReadyStateChange-</b><br />
It is called whenever readystate attribute changes. It must not be used with synchronous requests.<br />
<b><br />
</b> <b>readyState-</b><br />
represents the state of the request. It ranges from 0 to 4.<br />
<b>0 UNOPENED</b> open() is not called.<br />
<b>1 OPENED </b>open is called but send() is not called.<br />
<b>2 HEADERS_RECEIVED </b>send() is called, and headers and status are available.<br />
<b>3 LOADING </b>Downloading data; responseText holds the data.<br />
<b>4 DONE </b>The operation is completed fully.</p>
<p><b>reponseText-</b><br />
returns response as text.</p>
<p><b>responseXML-</b><br />
returns response as XML</p>
<p><b>Methods of XMLHttpRequest object-</b></p>
<p>The important methods of XMLHttpRequest object are as follows:</p>
<p><b>void open(method, URL):</b><br />
opens the request specifying get or post method and url.</p>
<p><b>void open(method, URL, async):</b><br />
same as above but specifies asynchronous or not.</p>
<p><b>void open(method, URL, async, username, password):</b><br />
same as above but specifies username and password.</p>
<p><b>void send():</b><br />
sends get request.</p>
<p><b>void send(string):</b><br />
send post request.</p>
<p><b>setRequestHeader(header,value):</b><br />
it adds request headers.</p>
<p>Despite its name, XMLHttpRequest can be used to retrieve any type of data, not just XML, and it supports protocols other than HTTP (including file and ftp).</p>
<p><b>Create an XMLHttpRequest Object-</b></p>
<p>To create an instance of XMLHttpRequest, simply do this:</p>
<p><i>var myRequest = new XMLHttpRequest();</i></p>
<p>Old versions of Internet Explorer (IE5 and IE6) use an ActiveX Object:</p>
<p><i>var xmlhttp=new ActiveXObject(&#8220;Microsoft.XMLHTTP&#8221;);</i></p>
</div>
<div style="background-color: pink; border-width: thin; text-align: center;"><b><;<;<a href="https://dineshonjava.com/asynchronous-vs-synchronous-ajax/">Previous</a> <;<; || <a href="https://dineshonjava.com/ajax-tutorial/">Index </a>|| >;>;<a href="https://dineshonjava.com/xmlhttprequest-object-in-ajax/">Next</a> >;>;</b></div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/asynchronous-vs-synchronous-ajax/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '195'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…