... Ajax can I use it or not ...• Ajax - can I use it or not »»Quote from Wikipedia: A while back I was wondering how can I make use of this technology and still have the website accessible by visitors that doesn’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. 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. Let’s dig in step by step. // 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 && typeof XMLHttpRequest != ‘undefined’) ewd_ret = new XMLHttpRequest(); return ewd_ret; } second will create the function that will handle the cookie 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 this is the php function that will handle the cookie state and create the url 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 } } then on the page you will be using the above function to handle how the a href tag are written to the page: link_url($url_link,$div_name)
Source: web-design-ireland |
pub: 14 Oct 2007 by: Louie Eire Web Design | added: 26 Feb 2008 | cat: Ajax | views: 49 time/s
|
Categories
|
Channels
Press Release
|