<?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>Website Design Ireland, Website Development &#187; ajax technologies</title>
	<atom:link href="http://www.eire-webdesign.ie/blog/tag/ajax-technologies/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.eire-webdesign.ie/blog</link>
	<description>Web Design and Development</description>
	<lastBuildDate>Sat, 02 Jan 2010 14:53:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Ajax &#8211; can I use it or not?</title>
		<link>http://www.eire-webdesign.ie/blog/2007/10/14/Ajax-can-I-use-it-or-not/</link>
		<comments>http://www.eire-webdesign.ie/blog/2007/10/14/Ajax-can-I-use-it-or-not/#comments</comments>
		<pubDate>Sun, 14 Oct 2007 14:48:04 +0000</pubDate>
		<dc:creator>Louie @ Eire Web Design</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ajax and php]]></category>
		<category><![CDATA[ajax technologies]]></category>

		<guid isPermaLink="false">http://www.eire-webdesign.ie/blog/?p=1</guid>
		<description><![CDATA[Quote from Wikipedia:  &#8221;Ajax, shorthand for Asynchronous JavaScript and XML, is a web development technique for creating interactive web applications.   The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire web page does not have to be reloaded [...]]]></description>
			<content:encoded><![CDATA[<p>Quote from Wikipedia:<br />
 &#8221;Ajax, shorthand for Asynchronous JavaScript and XML, is a web development technique for creating interactive web applications.<br />
  The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire web page does not have to be reloaded each time the user makes a change.<br />
  This is meant to increase the web page&#8217;s interactivity, speed, and usability. &#8221;<br />
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::</p>
<p>A while back I was wondering how can I make use of this technology and still have the website accessible by visitors that doesn&#8217;t have JavaScript enabled browser and can not make use of the XMLHttpRequest and also have the search engine spidering the website without any problems.</p>
<p>The solution I came up with was to create an instance of the XMLHttpRequest and store a cookie on the user computer with the value received.<br />
If the instance is successfully created we store a cookie &#8220;xml_state&#8221; with the value &#8220;yes&#8221; for 1 day (24 hours), if not then a cookie &#8220;xml_state&#8221; with the value &#8220;no&#8221; will be set instead.<br />
Then using the request cookie method we can handle how we are writing the &#8220;a href&#8221; tags.<br />
I have this done using PHP, by creating another function to handle the way the links will be written.</p>
<p>Let&#8217;s dig in step by step.</p>
<pre lang="javascript">// first create the XMLHTTP function
// Create XMLHTTP - Note: AJAX feature requires IE5.5+, FF1+, and NS6.2+
function EWD_createXMLHttp() {
if (!(document.getElementsByTagName || document.all))
  return;
  var ewd_ret= null;
  try {
    ewd_ret = new ActiveXObject('Msxml2.XMLHTTP');
  } catch (e) {
    try {
      ewd_ret = new ActiveXObject('Microsoft.XMLHTTP');
   } catch (ee) {
  ewd_ret = null;
  }
}
if (!ewd_ret &amp;&amp; typeof XMLHttpRequest != 'undefined')
  ewd_ret = new XMLHttpRequest();
  return ewd_ret;
}</pre>
<p>second will create the function that will handle the cookie</p>
<pre lang="javascript">function EWD_SetCookie(cookieName,cookieValue,nDays) {
  var today = new Date();
  var expire = new Date();
  if (nDays==null || nDays==0) nDays=1;
  //we set the cookie to one day just in case the visitors decides to make changes to the browser
  expire.setTime(today.getTime() + 3600000*24*nDays);
  document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}
//end of set cookie     

//check for XMLHTTP support
var xmlHttp = EWD_createXMLHttp();
if (xmlHttp){
  EWD_SetCookie("xml_state","yes",1);
}else{
  EWD_SetCookie("xml_state","no",1);
}
//end of check for XMLHTTP</pre>
<p>this is the php function that will handle the cookie state and create the url</p>
<pre lang="php">function link_url($url_link,$div_name){
  if(@$_COOKIE['xml_state'] == "yes") {
    //we can use ajax
    $url_link = '$url_link' onclick='ajax_function_that_will_make_the_request($url_link, $div_name); return false;'
    return $url_link; //return ajax type a href
  }else{
    return $url_link; //return normal a href
  }
}</pre>
<p>then on the page you will be using the above function to handle how the a href tag are written to the page:</p>
<pre lang="php">link_url($url_link,$div_name)</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.eire-webdesign.ie/blog/2007/10/14/Ajax-can-I-use-it-or-not/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
