<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>» DoYourself.org &#187; ajax</title>
	<atom:link href="http://www.doyourself.org/category/ajax/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.doyourself.org</link>
	<description>Did you know ?</description>
	<lastBuildDate>Fri, 03 Feb 2012 23:00:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>FAQ on AJAX Technology</title>
		<link>http://www.doyourself.org/ajax/543-faq-on-ajax-technology/</link>
		<comments>http://www.doyourself.org/ajax/543-faq-on-ajax-technology/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 20:14:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[FAQ]]></category>
		<category><![CDATA[on]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.doyourself.org/?p=543</guid>
		<description><![CDATA[AJAX has become an hot technology with Web2.0 but before starting AJAX Programming developers needs to know some important FAQ on AJAX. Q) Ajax an Microsoft Technology? A) Absolutely No, Ajax is an cross browser technology. It is browser dependent and uses JavaScript. Q)Are Ajax applications easier to develop than traditional web applications? A) Not [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>AJAX has become an hot technology with Web2.0 but before starting<br />
AJAX Programming developers needs to know some important FAQ on AJAX.<br />
<span></span></p>
<p><strong>Q) Ajax an Microsoft Technology?</strong><br />
A) Absolutely No, Ajax is an cross browser technology. It is browser dependent and uses JavaScript.<br />
<strong>Q)Are Ajax applications easier to develop than traditional web applications? </strong><br />
A) Not necessarily. Ajax applications can involve complex JavaScript<br />
code on the client. To develop that complex code efficient and bug-free<br />
is not an simple task as it involves pure JavaScript &amp; DHTML<br />
coding. But better development tools and frameworks are require to make<br />
the Ajax Application development much faster and easier.<br />
<strong>Q) Do Ajax applications always deliver a better experience than traditional web applications? </strong><br />
A) Not necessarily. Ajax gives interaction designers more flexibility.<br />
However, the more power we have, the more caution we must use in<br />
exercising it. We must be careful to use Ajax to enhance the user<br />
experience of our applications, not degrade it.<br />
<strong>Q) Apart from AJAX any other Technique exist for Dynamic Web Page Update?</strong><br />
A)  IFRAMES<br />
<strong>Q) Can AJAX access Server side script residing on different domain?</strong><br />
A) NO. Ajax can only access the Script residing on same domain. If you<br />
try to access the script from other domain browsers gives an error<br />
â€œAccess Deniedâ€<br />
<strong>Q) Ajax can also fetch XML content from server side, if this is true how?</strong><br />
A) Using responseXML properties and then by using JavaScript XML DOM to access the attributes and value of XML data.<br />
<strong>Q) Is Ajax is Browser Dependent?</strong><br />
A) Yes, Ajax object is part of JavaScript engine inside every browser.<br />
So if a new browser comes into market and the JavaScript engine doesnâ€™t<br />
have XMLHTTP object then Ajax will not work.<br />
<strong>Q) How can i check the progress of my Ajax call?</strong><br />
A) When making Ajax call the readystate has to reach 4 to capture the<br />
remote date. So you can insert appropriate messages until the<br />
readystate reaches 4.<br />
<strong>Q) Do i have to wait endlessly after making Ajax Call?</strong><br />
A) Not always but there are some exceptional cases when the remote<br />
server is already busy and is unable to handle your request in that<br />
case the JavaScript code will wait until response is fetched from the<br />
remote server or there is browser request timed out. You can use the<br />
interval to make another call after specific interval.<br /><strong>Q) Do i have to explicitly use Ajax Frameworks for implementing Ajax?</strong><br />
A) Not necessarily, Ajax Frameworks are meant to make the life of<br />
programmers simpler. These frameworks acts as an wrapper to the Ajax<br />
Code, they provide you with the function call that will do all the Ajax<br />
Call and you donâ€™t have to write the Basic Ajax Code.<br />
<strong>Q) Can Ajax work with all Web Technologies?</strong><br />
A) Yes, Ajax is browser dependent and if the web technology you are using supports browser then Ajax will work.<br />
<strong>Q) Can i make multiple Ajax Call?</strong><br />
A) Yes you can make multiple Ajax call provided you have separate Ajax<br />
Object variables created. Making another Ajax Call on the existing Ajax<br />
Object will overwrite the previous make call.<br />
<strong>Q) Can i do Ajax Connection Pooling Techniques?</strong><br />
A) Yes you can do connection pooling for making Ajax call. Here you<br />
will be storing all the Ajax objects in a connection pool so that every<br />
individual object will perform their own task.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doyourself.org/ajax/543-faq-on-ajax-technology/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>FORM POST in PHP using AJAX</title>
		<link>http://www.doyourself.org/ajax/542-form-post-in-php-using-ajax/</link>
		<comments>http://www.doyourself.org/ajax/542-form-post-in-php-using-ajax/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 20:14:09 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[in]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[using]]></category>

		<guid isPermaLink="false">http://www.doyourself.org/?p=542</guid>
		<description><![CDATA[This example demonstrates HTTP FORM POST complete HTML form to the server and displaying the response using AJAX. HTML Page &#60;html&#62;&#60;head&#62;&#60;title&#62;PHP using AJAX&#60;/title&#62;&#60;script type="text/javascript"&#62;&#160;var time_variable;&#160;function getXMLObject() //XML OBJECT{ var xmlHttp = false; try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>This example demonstrates HTTP FORM POST complete HTML form to the server and displaying the response using AJAX.<br />
<span></span><br />
<strong>HTML Page</strong></p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace">&lt;html&gt;&lt;head&gt;&lt;title&gt;PHP using AJAX&lt;/title&gt;<span>&lt;</span>script type<span>=</span><span>"text/javascript"</span><span>&gt;</span>&nbsp;<span>var</span> time_variable<span>;</span>&nbsp;<span>function</span> getXMLObject<span>(</span><span>)</span>  <span>//XML OBJECT</span><span>{</span>   <span>var</span> xmlHttp <span>=</span> <span>false</span><span>;</span>   <span>try</span> <span>{</span>     xmlHttp <span>=</span> <span>new</span> ActiveXObject<span>(</span><span>"Msxml2.XMLHTTP"</span><span>)</span>  <span>// For Old Microsoft Browsers</span>   <span>}</span>   <span>catch</span> <span>(</span>e<span>)</span> <span>{</span>     <span>try</span> <span>{</span>       xmlHttp <span>=</span> <span>new</span> ActiveXObject<span>(</span><span>"Microsoft.XMLHTTP"</span><span>)</span>  <span>// For Microsoft IE 6.0+</span>     <span>}</span>     <span>catch</span> <span>(</span>e2<span>)</span> <span>{</span>       xmlHttp <span>=</span> <span>false</span>   <span>// No Browser accepts the XMLHTTP Object then false</span>     <span>}</span>   <span>}</span>   <span>if</span> <span>(</span><span>!</span>xmlHttp <span>&amp;&amp;</span> <span>typeof</span> XMLHttpRequest <span>!=</span> <span>'undefined'</span><span>)</span> <span>{</span>     xmlHttp <span>=</span> <span>new</span> XMLHttpRequest<span>(</span><span>)</span><span>;</span>        <span>//For Mozilla, Opera Browsers</span>   <span>}</span>   <span>return</span> xmlHttp<span>;</span>  <span>// Mandatory Statement returning the ajax object created</span><span>}</span>&nbsp;<span>var</span> xmlhttp <span>=</span> <span>new</span> getXMLObject<span>(</span><span>)</span><span>;</span>	<span>//xmlhttp holds the ajax object</span>&nbsp;<span>function</span> ajaxFunction<span>(</span><span>)</span> <span>{</span>  <span>var</span> getdate <span>=</span> <span>new</span> Date<span>(</span><span>)</span><span>;</span>  <span>//Used to prevent caching during ajax call</span>  <span>if</span><span>(</span>xmlhttp<span>)</span> <span>{</span>   	<span>var</span> txtname <span>=</span> document.<span>getElementById</span><span>(</span><span>"txtname"</span><span>)</span><span>;</span>    xmlhttp.<span>open</span><span>(</span><span>"POST"</span><span>,</span><span>"testing.php"</span><span>,</span><span>true</span><span>)</span><span>;</span> <span>//calling testing.php using POST method</span>    xmlhttp.<span>onreadystatechange</span>  <span>=</span> handleServerResponse<span>;</span>    xmlhttp.<span>setRequestHeader</span><span>(</span><span>'Content-Type'</span><span>,</span> <span>'application/x-www-form-urlencoded'</span><span>)</span><span>;</span>    xmlhttp.<span>send</span><span>(</span><span>"txtname="</span> <span>+</span> txtname.<span>value</span><span>)</span><span>;</span> <span>//Posting txtname to PHP File</span>  <span>}</span><span>}</span>&nbsp;<span>function</span> handleServerResponse<span>(</span><span>)</span> <span>{</span>   <span>if</span> <span>(</span>xmlhttp.<span>readyState</span> <span>==</span> <span>4</span><span>)</span> <span>{</span>     <span>if</span><span>(</span>xmlhttp.<span>status</span> <span>==</span> <span>200</span><span>)</span> <span>{</span>       document.<span>getElementById</span><span>(</span><span>"message"</span><span>)</span>.<span>innerHTML</span><span>=</span>xmlhttp.<span>responseText</span><span>;</span> <span>//Update the HTML Form element </span>     <span>}</span>     <span>else</span> <span>{</span>        <span>alert</span><span>(</span><span>"Error during AJAX call. Please try again"</span><span>)</span><span>;</span>     <span>}</span>   <span>}</span><span>}</span><span>&lt;/</span>script<span>&gt;</span>&lt;body&gt;&lt;form name="myForm"&gt;&lt;table&gt; &lt;tr&gt;  &lt;td&gt;Enter Name&lt;/td&gt;  &lt;td&gt;&lt;input type="text" name="txtname" id="txtname" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;  &lt;td colspan="2"&gt;&lt;input type="button" value="Submit" onclick="ajaxFunction();" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;&lt;div id="message" name="message"&gt;&lt;/div&gt; &lt;/form&gt;&lt;/body&gt;&lt;/head&gt;&lt;/html&gt;</pre>
</div>
</div>
<p><strong>PHP Code</strong></p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace"><span>&lt;</span> ?&nbsp;<span>$a</span> <span>=</span> <span>$_POST</span><span>[</span><span>'txtname'</span><span>]</span><span>;</span>&nbsp;<span>echo</span> <span>"Good Morning"</span><span>.</span><span>$a</span><span>;</span>&nbsp;&nbsp;<span>?&gt;

</span></pre>
<h2><strong>Explanation for the AJAX Code</strong></h2>
<p>Here i have declared 3 JavaScript function:<br />
<strong>getXMLObject()</strong> â€“ Responsible for creating the AJAX Object depending on the browser<br />
<strong>ajaxFunction()</strong> â€“ Responsible for calling PHP page through AJAX call<br />
<strong>handleServerResponse()</strong> â€“ Responsible for displaying the data retrieved from the server</p>
<p><strong>How the AJAX Code Works:</strong></p>
<ul>
<li>When the page loads i am creating an AJAX Object by calling the<br />
getXMLObject() function and returning the object created in the xmlhttp<br />
variable</li>
<li>When the user clicks on the input Button, ajaxFunction() gets<br />
called which checks for whether the Ajax Object is created or not and<br />
depending on that calls the remote script. Here a function handler<br />
handleServerResponse is also defined for retrieving the value from the<br />
server</li>
<li>When the readystate of the AJAX call reaches 4 and the http status<br />
is 200 we pass the data fetched from the server to the textbox</li>
</ul>
<h2><strong>Explanation for the PHP Code</strong></h2>
<ul>
<li>I am calling $_POST for fetching the post content send through Ajax Call</li>
<li>Finally i am calling echo to send the response back to the calling page</li>
</ul>
<pre style="font-family: monospace"></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.doyourself.org/ajax/542-form-post-in-php-using-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax Programming with JSP and Servlets</title>
		<link>http://www.doyourself.org/ajax/541-ajax-programming-with-jsp-and-servlets/</link>
		<comments>http://www.doyourself.org/ajax/541-ajax-programming-with-jsp-and-servlets/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 20:13:38 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[and]]></category>
		<category><![CDATA[JSP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Servlets]]></category>
		<category><![CDATA[with]]></category>

		<guid isPermaLink="false">http://www.doyourself.org/?p=541</guid>
		<description><![CDATA[In Java World Servlets are popularly used for Model View Controller (MVC) Design Pattern. This article will guide you on writing AJAX based application for fetching data from the Servlet and showing it on JSP page. JSP File Code: &#60;html&#62;&#60;head&#62;&#60;title&#62;JSP and Servlet using AJAX&#60;/title&#62;&#60;script type="text/javascript"&#62;&#160;function getXMLObject() //XML OBJECT{ var xmlHttp = false; try { xmlHttp [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>In Java World Servlets are popularly used for Model View Controller<br />
(MVC) Design Pattern. This article will guide you on writing AJAX based<br />
application for fetching data from the Servlet and showing it on JSP<br />
page.<br />
<span></span><br />
<strong>JSP File Code:</strong></p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace">&lt;html&gt;&lt;head&gt;&lt;title&gt;JSP and Servlet using AJAX&lt;/title&gt;<span>&lt;</span>script type<span>=</span><span>"text/javascript"</span><span>&gt;</span>&nbsp;<span>function</span> getXMLObject<span>(</span><span>)</span>  <span>//XML OBJECT</span><span>{</span>   <span>var</span> xmlHttp <span>=</span> <span>false</span><span>;</span>   <span>try</span> <span>{</span>     xmlHttp <span>=</span> <span>new</span> ActiveXObject<span>(</span><span>"Msxml2.XMLHTTP"</span><span>)</span>  <span>// For Old Microsoft Browsers</span>   <span>}</span>   <span>catch</span> <span>(</span>e<span>)</span> <span>{</span>     <span>try</span> <span>{</span>       xmlHttp <span>=</span> <span>new</span> ActiveXObject<span>(</span><span>"Microsoft.XMLHTTP"</span><span>)</span>  <span>// For Microsoft IE 6.0+</span>     <span>}</span>     <span>catch</span> <span>(</span>e2<span>)</span> <span>{</span>       xmlHttp <span>=</span> <span>false</span>   <span>// No Browser accepts the XMLHTTP Object then false</span>     <span>}</span>   <span>}</span>   <span>if</span> <span>(</span><span>!</span>xmlHttp <span>&amp;&amp;</span> <span>typeof</span> XMLHttpRequest <span>!=</span> <span>'undefined'</span><span>)</span> <span>{</span>     xmlHttp <span>=</span> <span>new</span> XMLHttpRequest<span>(</span><span>)</span><span>;</span>        <span>//For Mozilla, Opera Browsers</span>   <span>}</span>   <span>return</span> xmlHttp<span>;</span>  <span>// Mandatory Statement returning the ajax object created</span><span>}</span>&nbsp;<span>var</span> xmlhttp <span>=</span> <span>new</span> getXMLObject<span>(</span><span>)</span><span>;</span>	<span>//xmlhttp holds the ajax object</span>&nbsp;<span>function</span> ajaxFunction<span>(</span><span>)</span> <span>{</span>  <span>var</span> getdate <span>=</span> <span>new</span> Date<span>(</span><span>)</span><span>;</span>  <span>//Used to prevent caching during ajax call</span>  <span>if</span><span>(</span>xmlhttp<span>)</span> <span>{</span>     xmlhttp.<span>open</span><span>(</span><span>"GET"</span><span>,</span><span>"gettime?"</span> <span>+</span> getdate.<span>getTime</span><span>(</span><span>)</span><span>,</span><span>true</span><span>)</span><span>;</span> <span>//gettime will be the servlet name</span>    xmlhttp.<span>onreadystatechange</span>  <span>=</span> handleServerResponse<span>;</span>    xmlhttp.<span>setRequestHeader</span><span>(</span><span>'Content-Type'</span><span>,</span> <span>'application/x-www-form-urlencoded'</span><span>)</span><span>;</span>    xmlhttp.<span>send</span><span>(</span><span>null</span><span>)</span><span>;</span>  <span>}</span><span>}</span>&nbsp;<span>function</span> handleServerResponse<span>(</span><span>)</span> <span>{</span>   <span>if</span> <span>(</span>xmlhttp.<span>readyState</span> <span>==</span> <span>4</span><span>)</span> <span>{</span>     <span>if</span><span>(</span>xmlhttp.<span>status</span> <span>==</span> <span>200</span><span>)</span> <span>{</span>       document.<span>myForm</span>.<span>time</span>.<span>value</span><span>=</span>xmlhttp.<span>responseText</span><span>;</span> <span>//Update the HTML Form element </span>     <span>}</span>     <span>else</span> <span>{</span>        <span>alert</span><span>(</span><span>"Error during AJAX call. Please try again"</span><span>)</span><span>;</span>     <span>}</span>   <span>}</span><span>}</span><span>&lt;/</span>script<span>&gt;</span>&lt;body&gt;&lt;form name="myForm"&gt;Server Time:&lt;input type="text" name="time" /&gt;&lt;br /&gt;&lt;input type="button" onClick="javascript:ajaxFunction();" value="Click to display Server Time on Textbox"/&gt;&lt;br /&gt;&lt;/form&gt;&lt;/body&gt;&lt;/head&gt;&lt;/html&gt;</pre>
</div>
</div>
<h2><strong>Explanation for the AJAX Code</strong></h2>
<p>Here i have declared 3 JavaScript function:<br />
<strong>getXMLObject()</strong> â€“ Responsible for creating the AJAX Object depending on the browser.<br />
<strong>ajaxFunction()</strong> â€“ Responsible for calling servlet through AJAX call.<br />
<strong>handleServerResponse()</strong> â€“ Responsible for displaying the data retrieved from the server.</p>
<p><strong>How the AJAX Code Works:</strong></p>
<ul>
<li>When the page loads i am creating an AJAX Object by calling the<br />
getXMLObject() function and returning the object created in the xmlhttp<br />
variable</li>
<li>When the user clicks on the input Button, ajaxFunction() gets<br />
called which checks for whether the Ajax Object is created or not and<br />
depending on that calls the remote script. Here a function handler<br />
handleServerResponse is also defined for retrieving the value from the<br />
server</li>
<li>When the readystate of the AJAX call reaches 4 and the http status<br />
is 200 we pass the data fetched from the server to the textbox</li>
</ul>
<p><strong>Servlet Code</strong></p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace"><span>import</span> <span>java.io.*</span><span>;</span>&nbsp;<span>import</span> <span>java.text.*</span><span>;</span>&nbsp;<span>import</span> <span>java.util.*</span><span>;</span>&nbsp;<span>import</span> <span>javax.servlet.*</span><span>;</span>&nbsp;<span>import</span> <span>javax.servlet.http.*</span><span>;</span>&nbsp;<span>public</span> <span>class</span> gettime <span>extends</span> HttpServlet <span>{</span>&nbsp;	<span>public</span> <span>void</span> init<span>(</span>ServletConfig config<span>)</span> <span>throws</span> ServletException <span>{</span>			<span>super</span>.<span>init</span><span>(</span>config<span>)</span><span>;</span>	<span>}</span>&nbsp;	<span>public</span> <span>void</span> destroy<span>(</span><span>)</span> <span>{</span>&nbsp;	<span>}</span>&nbsp;	<span>public</span> <span>void</span> doPost<span>(</span>HttpServletRequest request,HttpServletResponse response<span>)</span> <span>throws</span> <span>IOException</span>, ServletException <span>{</span>		<span>PrintWriter</span> out <span>=</span> response.<span>getWriter</span><span>(</span><span>)</span><span>;</span>		<span>Date</span> df <span>=</span> <span>new</span> <span>Date</span><span>(</span><span>)</span><span>;</span>		out.<span>println</span><span>(</span>df.<span>getTime</span><span>(</span><span>)</span><span>)</span><span>;</span>	<span>}</span>&nbsp;	<span>public</span> <span>void</span> doGet<span>(</span>HttpServletRequest request,HttpServletResponse response<span>)</span> <span>throws</span> <span>IOException</span>, ServletException <span>{</span>		doPost<span>(</span>request,response<span>)</span><span>;</span>	<span>}</span><span>}</span></pre>
</div>
</div>
<h2><strong>Explanation for the Servlet Code</strong></h2>
<ul>
<li>By default doGet function gets called and i am redirecting the control to doPost function whenever doGet function is called</li>
<li>In doPost function i am creating the date object and displaying the current time using the getTime() method of Date class</li>
<li>So all the displaying content gets passed to the Ajax Object in the form of response</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.doyourself.org/ajax/541-ajax-programming-with-jsp-and-servlets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTTP Form POST Request using AJAX and Servlet</title>
		<link>http://www.doyourself.org/ajax/540-http-form-post-request-using-ajax-and-servlet/</link>
		<comments>http://www.doyourself.org/ajax/540-http-form-post-request-using-ajax-and-servlet/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 20:12:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[and]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[POST]]></category>
		<category><![CDATA[Request]]></category>
		<category><![CDATA[Servlet]]></category>
		<category><![CDATA[using]]></category>

		<guid isPermaLink="false">http://www.doyourself.org/?p=540</guid>
		<description><![CDATA[In Java World Servlets are popularly used for Model View Controller(MVC) Design Pattern. This article will guide you on writing AJAX based application that will post data to Servlet and will fetching the computed data from the Servlet. With this approach the page will get the updated content from the server without refreshing the jsp/html [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>In Java World Servlets are popularly used for Model View<br />
Controller(MVC) Design Pattern. This article will guide you on writing<br />
AJAX based application that will post data to Servlet and will fetching<br />
the computed data from the Servlet. With this approach the page will<br />
get the updated content from the server without refreshing the jsp/html<br />
page.<br />
<span></span><br />
<strong>JSP Code: </strong></p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace">&lt;html&gt;&lt;head&gt;&lt;title&gt;JSP and Servlet using AJAX&lt;/title&gt;<span>&lt;</span>script type<span>=</span><span>"text/javascript"</span><span>&gt;</span>&nbsp;<span>function</span> getXMLObject<span>(</span><span>)</span>  <span>//XML OBJECT</span><span>{</span>   <span>var</span> xmlHttp <span>=</span> <span>false</span><span>;</span>   <span>try</span> <span>{</span>     xmlHttp <span>=</span> <span>new</span> ActiveXObject<span>(</span><span>"Msxml2.XMLHTTP"</span><span>)</span>  <span>// For Old Microsoft Browsers</span>   <span>}</span>   <span>catch</span> <span>(</span>e<span>)</span> <span>{</span>     <span>try</span> <span>{</span>       xmlHttp <span>=</span> <span>new</span> ActiveXObject<span>(</span><span>"Microsoft.XMLHTTP"</span><span>)</span>  <span>// For Microsoft IE 6.0+</span>     <span>}</span>     <span>catch</span> <span>(</span>e2<span>)</span> <span>{</span>       xmlHttp <span>=</span> <span>false</span>   <span>// No Browser accepts the XMLHTTP Object then false</span>     <span>}</span>   <span>}</span>   <span>if</span> <span>(</span><span>!</span>xmlHttp <span>&amp;&amp;</span> <span>typeof</span> XMLHttpRequest <span>!=</span> <span>'undefined'</span><span>)</span> <span>{</span>     xmlHttp <span>=</span> <span>new</span> XMLHttpRequest<span>(</span><span>)</span><span>;</span>        <span>//For Mozilla, Opera Browsers</span>   <span>}</span>   <span>return</span> xmlHttp<span>;</span>  <span>// Mandatory Statement returning the ajax object created</span><span>}</span>&nbsp;<span>var</span> xmlhttp <span>=</span> <span>new</span> getXMLObject<span>(</span><span>)</span><span>;</span>	<span>//xmlhttp holds the ajax object</span>&nbsp;<span>function</span> ajaxFunction<span>(</span><span>)</span> <span>{</span>  <span>if</span><span>(</span>xmlhttp<span>)</span> <span>{</span>   	<span>var</span> txtname <span>=</span> document.<span>getElementById</span><span>(</span><span>"txtname"</span><span>)</span><span>;</span>    xmlhttp.<span>open</span><span>(</span><span>"POST"</span><span>,</span><span>"getname"</span><span>,</span><span>true</span><span>)</span><span>;</span> <span>//getname will be the servlet name</span>    xmlhttp.<span>onreadystatechange</span>  <span>=</span> handleServerResponse<span>;</span>    xmlhttp.<span>setRequestHeader</span><span>(</span><span>'Content-Type'</span><span>,</span> <span>'application/x-www-form-urlencoded'</span><span>)</span><span>;</span>    xmlhttp.<span>send</span><span>(</span><span>"txtname="</span> <span>+</span> txtname.<span>value</span><span>)</span><span>;</span> <span>//Posting txtname to Servlet</span>  <span>}</span><span>}</span>&nbsp;<span>function</span> handleServerResponse<span>(</span><span>)</span> <span>{</span>   <span>if</span> <span>(</span>xmlhttp.<span>readyState</span> <span>==</span> <span>4</span><span>)</span> <span>{</span>     <span>if</span><span>(</span>xmlhttp.<span>status</span> <span>==</span> <span>200</span><span>)</span> <span>{</span>       document.<span>myForm</span>.<span>message</span>.<span>innerHTML</span><span>=</span>xmlhttp.<span>responseText</span><span>;</span> <span>//Update the HTML Form element </span>     <span>}</span>     <span>else</span> <span>{</span>        <span>alert</span><span>(</span><span>"Error during AJAX call. Please try again"</span><span>)</span><span>;</span>     <span>}</span>   <span>}</span><span>}</span><span>&lt;/</span>script<span>&gt;</span>&lt;body&gt;&lt;form name="myForm" method="POST" action="getname"&gt;&lt;table&gt; &lt;tr&gt;  &lt;td&gt;Enter Name&lt;/td&gt;  &lt;td&gt;&lt;input type="text" name="txtname" id="txtname" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt;  &lt;td colspan="2"&gt;&lt;input type="button" value="Submit"  onclick="ajaxFunction();" /&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;&lt;div id="message"&gt;&lt;/div&gt; &lt;/form&gt;&lt;/body&gt;&lt;/head&gt;&lt;/html&gt;</pre>
</div>
</div>
<p><strong>Servlet Code</strong></p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace"><span>import</span> <span>java.io.*</span><span>;</span>&nbsp;<span>import</span> <span>java.text.*</span><span>;</span>&nbsp;<span>import</span> <span>java.util.*</span><span>;</span>&nbsp;<span>import</span> <span>javax.servlet.*</span><span>;</span>&nbsp;<span>import</span> <span>javax.servlet.http.*</span><span>;</span>&nbsp;<span>public</span> <span>class</span> getname <span>extends</span> HttpServlet <span>{</span>&nbsp;	<span>public</span> <span>void</span> init<span>(</span>ServletConfig config<span>)</span> <span>throws</span> ServletException <span>{</span>			<span>super</span>.<span>init</span><span>(</span>config<span>)</span><span>;</span>	<span>}</span>&nbsp;	<span>public</span> <span>void</span> destroy<span>(</span><span>)</span> <span>{</span>&nbsp;	<span>}</span>&nbsp;	<span>public</span> <span>void</span> doPost<span>(</span>HttpServletRequest request,HttpServletResponse response<span>)</span> <span>throws</span> <span>IOException</span>, ServletException <span>{</span>		<span>String</span> name <span>=</span> <span>null</span><span>;</span>		<span>PrintWriter</span> out <span>=</span> response.<span>getWriter</span><span>(</span><span>)</span><span>;</span>		<span>if</span><span>(</span>request.<span>getParameter</span><span>(</span><span>"txtname"</span><span>)</span> <span>!=</span> <span>null</span><span>)</span> <span>{</span>			name <span>=</span> request.<span>getParameter</span><span>(</span><span>"txtname"</span><span>)</span><span>;</span>		<span>}</span>                <span>else</span> <span>{</span>                       name <span>=</span> <span>""</span><span>;</span>                <span>}</span>  	        out.<span>println</span><span>(</span><span>"You have successfully made Ajax Call:"</span> <span>+</span> name<span>)</span><span>;</span>	<span>}</span><span>}</span></pre>
</div>
</div>
<h2><strong>Explanation for the AJAX Code</strong></h2>
<p>Here i have declared 3 JavaScript function:<br />
<strong>getXMLObject()</strong> â€“ Responsible for creating the AJAX Object depending on the browser.<br />
<strong>ajaxFunction()</strong> â€“ Responsible for calling servlet through AJAX call.<br />
<strong>handleServerResponse()</strong> â€“ Responsible for displaying the data retrieved from the server.</p>
<p><strong>How the AJAX Code Works:</strong></p>
<ul>
<li>When the page loads i am creating an AJAX Object by calling the<br />
getXMLObject() function and returning the object created in the xmlhttp<br />
variable</li>
<li>When the user clicks on the input Button, ajaxFunction() gets<br />
called which checks for whether the Ajax Object is created or not and<br />
depending on that calls the remote script. Here a function handler<br />
handleServerResponse is also defined for retrieving the value from the<br />
server</li>
<li>When the readystate of the AJAX call reaches 4 and the http status<br />
is 200 we pass the data fetched from the server to the textbox</li>
</ul>
<p>
<h2><strong>Explanation for the Servlet Code</strong></h2>
<ul>
<li>By default doPost function gets called when you post the content to the servlet</li>
<li>In doPost function i am fetching the POST data in the form of txtname and assigning it to the local variable name</li>
<li>Finally i am displaying the data got through POST. All the<br />
displayed data gets passed to the Ajax Object in the form of response<br />
to the Ajax call made to the servlet</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.doyourself.org/ajax/540-http-form-post-request-using-ajax-and-servlet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax Programming using Prototype Framework</title>
		<link>http://www.doyourself.org/ajax/539-ajax-programming-using-prototype-framework/</link>
		<comments>http://www.doyourself.org/ajax/539-ajax-programming-using-prototype-framework/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 20:12:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Prototype]]></category>
		<category><![CDATA[using]]></category>

		<guid isPermaLink="false">http://www.doyourself.org/?p=539</guid>
		<description><![CDATA[Prototype is the most widely used framework for Ajax Operation. The main advantage of using Prototype Ajax Framework is its simplicity to use, automatically implements cross-browser and it offers bundle of utility function that can be used in your JavaScript code. This article will list down various ways by which you can make Ajax call [...]]]></description>
			<content:encoded><![CDATA[<p></p><p><a href="http://www.prototypejs.org/">Prototype</a> is the most<br />
widely used framework for Ajax Operation. The main advantage of using<br />
Prototype Ajax Framework is its simplicity to use, automatically<br />
implements cross-browser and it offers bundle of utility function that<br />
can be used in your JavaScript code. This article will list down<br />
various ways by which you can make Ajax call using Prototype Framework.<br />
This tutorial does not go into detailed implementation but shows you<br />
how we can do basic Ajax Call using Prototype Ajax Framework.<br />
<span></span></p>
<p>In Prototype there are three ways you can make Ajax calls.<br />
1) Ajax.Request<br />
2) Ajax.PeriodicalUpdater<br />
3) Ajax.Updater</p>
<p>Before we move into learning of individual Ajax call we also need to<br />
understand the various events and parameters getting used while making<br />
Ajax Call.</p>
<p><strong>Various Parameters Of the Object Passed to Ajax.Request:</strong><br />
<strong>method</strong><br />
This can be HTTP GET or HTTP POST. By default method defined is POST.</p>
<p><strong>parameters</strong><br />
This holds the key-value pair of the data that we are going to pass to<br />
the request page. This is the same data that we pass through the query<br />
string while calling remote URL.</p>
<p><strong>frequency</strong><br />
Here you specify the period in seconds wherein Ajax call will be made.</p>
<p><strong>decay</strong><br />
This is used to increase the interval time for Ajax call if there is no<br />
change in response. The amount of interval getting increased is the<br />
frequency*decay. This ensure that we do not make unecessary Ajax call<br />
for the same response getting from the server.</p>
<p><strong>Prototype Ajax Events:</strong><br />
<strong>onCreate:</strong><br />
This event get called whenever an new ajax request call is made. This<br />
is useful when we want to show an loading image indicating ajax call.</p>
<p><strong>onSuccess:</strong><br />
This event get called whenever the request is complete and the status code returned is in 2xx series.</p>
<p><strong>onFailure:</strong><br />
This event get called whenever the request is complete and the status code returned is not in 2xx series.</p>
<p><strong>onComplete:</strong><br />
This event get called whenever the request is complete and the<br />
connection request life cycle is complete. This event gets called after<br />
onSuccess and onFailure event. In this event we normally hide the<br />
loading image.</p>
<p><strong>Reading Request Response:</strong><br />
With prototype framework we can read either String, XML and <strong>JSON</strong><br />
content. String content can be read by calling responseText method, XML<br />
content can be read by calling responseXML and JSON content can be read<br />
by calling responseJSON method.</p>
<p><strong>Ajax.Request:</strong><br />
Here we make an single ajax request to an server page and after<br />
receiving the response from server the connection is terminated. The<br />
simple implement for the same is</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace">	<span>var</span> url <span>=</span> <span>"http://www.hiteshagrawal.com/uploads/ajax_time.php"</span><span>;</span>	<span>var</span> ajaxObjhttp <span>=</span> <span>new</span> Ajax.<span>Request</span><span>(</span>url<span>,</span> <span>{</span>		method<span>:</span> <span>'POST'</span><span>,</span>		parameters<span>:</span> <span>{</span>operation<span>:</span> <span>"readRecord"</span><span>}</span><span>,</span>                onCreate<span>:</span> <span>function</span><span>(</span>transport<span>)</span> <span>{</span>        	      <span>alert</span><span>(</span><span>"Creating New Ajax Call"</span><span>)</span><span>;</span>                <span>}</span><span>,</span>                onSuccess<span>:</span> <span>function</span><span>(</span>transport<span>)</span> <span>{</span>                      <span>var</span> serverResponse <span>=</span> transport.<span>responseText</span><span>;</span>                <span>}</span><span>,</span>                onFailure <span>:</span> <span>function</span><span>(</span>response<span>)</span> <span>{</span>                      <span>alert</span><span>(</span><span>"Some error occured while making call to remote server"</span><span>)</span><span>;</span>                <span>}</span>        <span>}</span><span>)</span><span>;</span></pre>
</div>
</div>
<p>Here we make an object of <strong>Ajax.Request</strong>. This<br />
objects accepts 2 parameter the first parameter is the request page url<br />
and another object which holds the essential information that we will<br />
be sending/receiving from the server page. On successful receiving the<br />
data from the requested page we read the data by calling responseText<br />
method.<br /><strong>Ajax.PeriodicalUpdater:</strong><br />
Here we provide an timer interval so that ajax request can be made at<br />
regular interval specified while making the ajax call. This can become<br />
handy when we want to show some live data that needs to be updated at<br />
regular interval.</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace">	<span>var</span> url <span>=</span> <span>"http://www.hiteshagrawal.com/uploads/ajax_time.php"</span><span>;</span>	<span>var</span> ajaxObjhttp <span>=</span> <span>new</span> Ajax.<span>PeriodicalUpdater</span><span>(</span><span>"textobj"</span><span>,</span> url<span>,</span> <span>{</span>		method<span>:</span> <span>'POST'</span><span>,</span>		frequency<span>:</span> <span>3</span><span>,</span>                decay<span>:</span> <span>2</span>         <span>}</span><span>)</span><span>;</span></pre>
</div>
</div>
<p>Here we make an object of <strong>Ajax.PeriodicalUpdaterRequest</strong>.<br />
This objects accepts 3 parameter the first paramter is the name of the<br />
DIV/SPAN control where the data will get updated, second parameter<br />
holds the request URL and third parameter holds an object which has the<br />
essential information that we will be sending/receiving from the server<br />
page.</p>
<p><strong>Ajax.Updater:</strong><br />
The only difference between Ajax.Request and Ajax.Updater is that in<br />
Ajax.Updater we specify the DIV/SPAN control name so now the data<br />
returned from server will get automatically updated within the DIV/SPAN<br />
control when the operation completes.</p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace">	<span>var</span> url <span>=</span> <span>"http://www.hiteshagrawal.com/uploads/ajax_time.php"</span><span>;</span>	<span>var</span> ajaxObjhttp <span>=</span> <span>new</span> Ajax.<span>Updater</span><span>(</span><span>"textobj"</span><span>,</span> url<span>,</span> <span>{</span>		parameters<span>:</span> <span>{</span> operation<span>:</span> <span>"readRecord"</span> <span>}</span>        <span>}</span><span>)</span><span>;</span></pre>
</div>
</div>
<p>Here we make an object of <strong>Ajax.Updater</strong>. This<br />
objects accepts 3 parameter the first parameter is the name of the<br />
DIV/SPAN where the data will get updated, second parameter holds the<br />
request URL and third parameter holds an object which has the essential<br />
information that we will be sending/receiving from the server page.</p>
<p>Example:<br />
In this example i am covering all the 3 Ajax call implementation.</p>
<p><strong>HTML Code:</strong></p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace">	&lt;html&gt;	&lt;head&gt;		&lt;title&gt;Prototype Ajax Call&lt;/title&gt;		&lt;script type="text/javascript" src="js/prototype.js"&gt;&lt;/script&gt;		&lt;script type="text/javascript"&gt;			function ajaxRequest() {				var url = "/uploads/ajax_time.php";				var ajaxObjhttp = new Ajax.Request(url, {					method: 'POST',					parameters: {operation: "readRecord"},			                onCreate: function(transport) {			        	       alert("Creating New Ajax Call");			                },			                onSuccess: function(transport) {			        		var textBoxObj = document.getElementById("ajaxRequestCall");			                        textBoxObj.innerHTML = transport.responseText;			                },			                onFailure : function(response) {			                       alert("Some error occured while making call to remote server");			               }			        });  			}&nbsp;    		        function ajaxUpdater() {				var url = "/uploads/ajax_time.php";				var textBoxObj = "ajaxUpdaterCall";				var ajaxObjhttp = new Ajax.Updater(textBoxObj, url, {					method: 'POST'	    		        });  			 }&nbsp;			function ajaxPeriodicUpdater() {				var url = "/uploads/ajax_time.php";				var textBoxObj = "ajaxPeriodicUpdaterCall";				var ajaxObjhttp = new Ajax.PeriodicalUpdater(textBoxObj, url, {					method: 'POST',					frequency: 3,	        		        decay: 2	    		        });   				}		&lt;/script&gt;	&lt;/head&gt;            &lt;body&gt;		Ajax Request: &lt;span id="ajaxRequestCall" name="ajaxRequestCall" style="border: 1px solid #CCCCCC"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;input type="button" onClick="ajaxRequest();" value="Ajax Request"/&gt;&lt;br /&gt;&lt;br /&gt;			Ajax Updater: &lt;span id="ajaxUpdaterCall" name="ajaxUpdaterCall" style="border: 1px solid #CCCCCC"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;input type="button" onClick="ajaxUpdater();" value="Ajax Updater"/&gt;&lt;br /&gt;&lt;br /&gt;		Ajax Periodic Updater: &lt;span id="ajaxPeriodicUpdaterCall" name="ajaxPeriodicUpdaterCall" style="border: 1px solid #CCCCCC"&gt;&amp;nbsp;&amp;nbsp;&lt;/span&gt;&amp;nbsp;&lt;input type="button" onClick="ajaxPeriodicUpdater();" value="Ajax Periodic Updater"/&gt;&lt;br /&gt;		&lt;/body&gt;&lt;/html&gt;</pre>
</div>
</div>
<p><strong>SERVER SIDE CODE (PHP):</strong></p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace"><span>&lt;</span> ?	<span>echo</span> <span>date</span><span>(</span><span>"H:i:s"</span><span>)</span><span>;</span><span>?&gt;</span></pre>
</div>
</div>
<p><strong>SERVER SIDE CODE (JSP):</strong></p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace"><span>&lt;</span> <span>%@</span>page import<span>=</span><span>"java.util.Date"</span><span>%&gt;</span><span>&lt;</span> <span>%</span>	<span>Date</span> currentDate <span>=</span> <span>new</span> <span>Date</span><span>(</span><span>)</span><span>;</span>	long currentTime <span>=</span> currentDate<span>.</span>getTime<span>(</span><span>)</span><span>;</span>	out<span>.</span>println<span>(</span>currentTime<span>)</span><span>;</span><span>%&gt;</span></pre>
</div>
</div>
<p>As per user working environment of the user whether PHP or JAVA i<br />
have written the server side code for both the language. The user only<br />
has to change the url in the javascript code.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.doyourself.org/ajax/539-ajax-programming-using-prototype-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trap Session TimeOut during Ajax Call</title>
		<link>http://www.doyourself.org/ajax/538-trap-session-timeout-during-ajax-call/</link>
		<comments>http://www.doyourself.org/ajax/538-trap-session-timeout-during-ajax-call/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 20:11:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ajax]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[Call]]></category>
		<category><![CDATA[during]]></category>
		<category><![CDATA[Session]]></category>
		<category><![CDATA[TimeOut]]></category>
		<category><![CDATA[Trap]]></category>

		<guid isPermaLink="false">http://www.doyourself.org/?p=538</guid>
		<description><![CDATA[Solving this issue has been an nightmare for me but finally i have achieve it some how, this may be not a full proof solution but it worked for me. This solution also has certain flaws which i also will be discuss in this article. Session TimeOut happen due to various reasons such as Server [...]]]></description>
			<content:encoded><![CDATA[<p></p><p>Solving this issue has been an nightmare for me but finally i have<br />
achieve it some how, this may be not a full proof solution but it<br />
worked for me. This solution also has certain flaws which i also will<br />
be discuss in this article.<br />
<span></span></p>
<p><strong>Session TimeOut</strong> happen due to various reasons such<br />
as Server clearing the session cookie after timeout period, user<br />
clearing the cache content from browser, Context Reload at Server etc.<br />
But if there is session timeout happens before making <strong>Ajax</strong><br />
Call the client machine may get abrupt error page if you are not<br />
trapping HTTP Status Code, this may not be due to Ajax call but session<br />
has cleared and the server id not able to process the requested page.</p>
<p>What i found is the data i am returning data from the <strong>Ajax</strong><br />
Call is an String HTML content that i want to show and whenever some<br />
thing happens at server end like session timeout the response i<br />
received from Server contains HTTP Status Code 500 message error. Under<br />
normal Ajax call i will not receive the HTTP Status Message so what i<br />
did is to check whether the response received from server contains <strong>HTTP Status Code 500</strong>.<br />
If it contains HTTP Status code i know that there is some unknown<br />
server error occurred and i am able to trap error occurred during Ajax<br />
Call.</p>
<p></p>
<p><strong>Ajax Code</strong></p>
<div class="wp_syntax">
<div class="code">
<pre style="font-family: monospace"><span>&lt;</span>script type<span>=</span><span>"text/javascript"</span><span>&gt;</span><span>var</span> xmlhttp <span>=</span> <span>new</span> getXMLObject<span>(</span><span>)</span><span>;</span><span>var</span> time_variable<span>;</span>&nbsp;<span>function</span> getXMLObject<span>(</span><span>)</span>  <span>//XML OBJECT</span><span>{</span>   <span>var</span> xmlHttp <span>=</span> <span>false</span><span>;</span>   <span>try</span> <span>{</span>     xmlHttp <span>=</span> <span>new</span> ActiveXObject<span>(</span><span>"Msxml2.XMLHTTP"</span><span>)</span>  <span>// For Old Microsoft Browsers</span>   <span>}</span>   <span>catch</span> <span>(</span>e<span>)</span> <span>{</span>     <span>try</span> <span>{</span>       xmlHttp <span>=</span> <span>new</span> ActiveXObject<span>(</span><span>"Microsoft.XMLHTTP"</span><span>)</span>  <span>// For Microsoft IE 6.0+</span>     <span>}</span>     <span>catch</span> <span>(</span>e2<span>)</span> <span>{</span>       xmlHttp <span>=</span> <span>false</span>   <span>// No Browser accepts the XMLHTTP Object then false</span>     <span>}</span>   <span>}</span>   <span>if</span> <span>(</span><span>!</span>xmlHttp <span>&amp;&amp;</span> <span>typeof</span> XMLHttpRequest <span>!=</span> <span>'undefined'</span><span>)</span> <span>{</span>     xmlHttp <span>=</span> <span>new</span> XMLHttpRequest<span>(</span><span>)</span><span>;</span>        <span>//For Mozilla, Opera Browsers</span>   <span>}</span>   <span>return</span> xmlHttp<span>;</span>  <span>// Mandatory Statement returning the ajax object created</span><span>}</span>&nbsp;<span>function</span> ajaxFunction<span>(</span><span>)</span> <span>{</span>  <span>var</span> getdate <span>=</span> <span>new</span> Date<span>(</span><span>)</span><span>;</span>  <span>//Used to prevent caching during ajax call</span>  <span>if</span><span>(</span>xmlhttp<span>)</span> <span>{</span>     xmlhttp.<span>open</span><span>(</span><span>"GET"</span><span>,</span><span>"ajax_time.php?"</span> <span>+</span> getdate.<span>getTime</span><span>(</span><span>)</span><span>,</span><span>true</span><span>)</span><span>;</span>    xmlhttp.<span>onreadystatechange</span>  <span>=</span> handleServerResponse<span>;</span>    xmlhttp.<span>send</span><span>(</span><span>null</span><span>)</span><span>;</span>  <span>}</span><span>}</span>&nbsp;<span>function</span> handleServerResponse<span>(</span><span>)</span> <span>{</span>   <span>if</span> <span>(</span>xmlhttp.<span>readyState</span> <span>==</span> <span>4</span><span>)</span> <span>{</span>     <span>if</span><span>(</span>xmlhttp.<span>status</span> <span>==</span> <span>200</span><span>)</span> <span>{</span>       document.<span>myForm</span>.<span>time</span>.<span>value</span><span>=</span>xmlhttp.<span>responseText</span><span>;</span> <span>//Update the HTML Form element </span>     <span>}</span> <span>else</span> <span>{</span>     	<span>if</span><span>(</span>xmlhttp.<span>status</span> <span>==</span> <span>500</span><span>)</span> <span>{</span>	        <span>alert</span><span>(</span><span>"Session TimeOut. Unable To Process Your Request"</span><span>)</span><span>;</span>                <span>//Process Further</span>	<span>}</span>    

As you can see you have made an successfully Ajax Call to the requestedpage so you receive readyState = 4 but during session timeOut thestatus code received from requested page is 500 and not 200 so now youcan write your code logic to handle session timeOut Error.

     <span>}</span>   <span>}</span><span>}</span><span>&lt;/</span>script<span>&gt;</span></pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.doyourself.org/ajax/538-trap-session-timeout-during-ajax-call/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

