{"id":40,"date":"2005-11-18T07:52:00","date_gmt":"2005-11-18T07:52:00","guid":{"rendered":"http:\/\/blog.trungson.com\/?p=40"},"modified":"2005-11-18T07:52:00","modified_gmt":"2005-11-18T07:52:00","slug":"rslite-a-cookie-based-ajax-solution","status":"publish","type":"post","link":"http:\/\/blog.trungson.com\/?p=40","title":{"rendered":"RSLite &#8211; A cookie-based AJAX solution"},"content":{"rendered":"<p>This is another solution written by Brent Ashley for asynchronous information fetching, way before the term AJAX were coined<br \/>\n<textarea name=\"code\" class=\"javascript\"><br \/>\nvar RSLite;<br \/>\nfunction RSLiteObject(){<br \/>\n this.interval = 1000;<br \/>\n this.attempts = 3;<br \/>\n this.i = new Image();<br \/>\n this.call = function (page){<br \/>\n  var d = new Date();<br \/>\n  document.cookie = &#8216;RSLite=x; expires=Fri, 31 Dec 1999 23:59:59 GMT; path=\/;&#8217;;<br \/>\n  this.i.src = page+&#8217;&#038;time=&#8217;+d.getTime();<br \/>\n  setTimeout(&#8220;RSLite.receive(1);&#8221;, this.interval );<br \/>\n }<br \/>\n this.receive = function ( attempt ){<br \/>\n  var response = null;<br \/>\n  var aCookie = document.cookie.split(&#8220;; &#8220;);<br \/>\n  for (var i=0; i < aCookie.length; i++){\n   var aCrumb = aCookie[i].split(\"=\");\n   if (aCrumb[0] == 'RSLite') response = aCrumb[1];\n  }\n  if ( response != null ){\n   this.callback( unescape(response.replace(\/\\+\/g,' ')) );\n  } else {\n   if (attempt < this.attempts){\n    setTimeout( \"RSLite.receive( \" + (attempt+1) +\" );\",this.interval);\n   } else { this.failure(); }\n  }    \n }\n this.callback = function( response ){ alert(response); }\n this.failure = function(){ \n  \/\/alert(\"Timed Out [\"+this.i.src+\"]\"); \/\/ disable for the time moment\n }\n}\n\nfunction myCallback(response) {\n \/\/ write the result back\n var tmpObj = document.getElementById('ResponseArea');\n if (tmpObj != null) {\n  tmpObj.innerHTML = response;\n } \/\/ if\n}\n\nRSLite = new RSLiteObject();\nRSLite.callback = myCallback;\n<\/textarea><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is another solution written by Brent Ashley for asynchronous information fetching, way before the term AJAX were coined var RSLite; function RSLiteObject(){ this.interval = 1000; this.attempts = 3; this.i = new Image(); this.call = function (page){ var d = new Date(); document.cookie = &#8216;RSLite=x; expires=Fri, 31 Dec 1999 23:59:59 GMT; path=\/;&#8217;; this.i.src = page+&#8217;&#038;time=&#8217;+d.getTime(); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/40"}],"collection":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=40"}],"version-history":[{"count":0,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.trungson.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}