<div id='msgHere'>
...loading today's quote</div>
<script type='text/javascript'>
var xmlhttp = null;
function AjaxRequest(url){
if(xmlhttp != null){
if(xmlhttp.abort)
xmlhttp.abort();
xmlhttp = null;
};
if(window.XMLHttpRequest) // good browsers
xmlhttp=new XMLHttpRequest();
else if(window.ActiveXObject) // IE
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if(xmlhttp == null)
return null;
xmlhttp.open("GET",url,false);
xmlhttp.send(null);
if(xmlhttp.status >= 200 && xmlhttp.status < 300)// 2xx is good enough
return xmlhttp.responseText;
else
return null;
}
function clearEle(element){
while(element.hasChildNodes())
element.removeChild(element.firstChild);
}
window.onload = function(){
var el, msg, date1, date2, txt = AjaxRequest('/files/quotes.txt');
date2 = new Date();
date2.setFullYear(2011);// year to begin
date2.setMonth(5);// take 1 from the month number
date2.setDate(6); // date of month
if(txt == null)
msg = 'page not found or Ajax not supported by your browser.';
else{
msg = txt;
}
date1 = new Date();
txt = msg.split("\n");
date1 = Math.floor(date1.getTime() / (24*60*60*1000));
date2 = Math.floor(date2.getTime() / (24*60*60*1000));
if(date1 > date2){// swap them around? -- replace with another method?
var tmp = date1;
date1 = date2;
date2 = tmp;
};
el = document.getElementById('msgHere');
clearEle(el);
el.appendChild( document.createTextNode(txt[(date2-date1)%txt.length]));
}
</script>
The steps taken are just adding the Custom HTML widget then pasting this code into it and giving it the title Daily Quotes 2 (I currently do have a plugin one on the page until I can get this one to work). All it does it display the Ajax message, “…loading today’s quote”. This code was copied from my old/original static HTML page where it did work (I recently converted from a static HTML site to WordPress).
I’ve even copied the code from the Daily Affirmations Custom HTML widget (because they’re identical) and changed the link and Ajax message, but that had the same result. The Affirmations one works, this one doesn’t. I even copied and pasted the Affirmations code and didn’t change anything, with the same result.
-
This reply was modified 6 years, 7 months ago by
Brenda.
-
This reply was modified 6 years, 7 months ago by
Brenda.
-
This reply was modified 6 years, 7 months ago by
Brenda.