Reputation: 441
I prefer to not use jQuery (as much as I understood the file is relately big and everytime the page loads it will "eat" a lot of bandwidth). I checked my code (below) that XMLHttpRequest is writted properly, and is NOT cross-domain. On Chrome is working properly, but on IE, if only one request is running then no problem, but the code below using 2 instances of XMLHttpRequest and BOTH somehow accessing my CGI but returns always empty string. I have tried also send(null), send("") or send('').
My code:
<script type="text/javascript">
var SMR;
var UPR;
var F;
var G;
function MUPD() {
F = window.setInterval(Updator, 5000);
G = window.setInterval(Listener, 5000);
if(typeof XMLHttpRequest !== 'undefined') { SMR = new XMLHttpRequest(); UPR = new XMLHttpRequest(); }
else {
var versions = ["MSXML2.XmlHttp.5.0",
"MSXML2.XmlHttp.4.0",
"MSXML2.XmlHttp.3.0",
"MSXML2.XmlHttp.2.0",
"Microsoft.XmlHttp"]
for(var i = 0, len = versions.length; i < len; i++) {
try {
SMR = new ActiveXObject(versions[i]);
UPR = new ActiveXObject(versions[i]);
break;
}
catch(e){}
}
}
}
function Updator() {
if (document.cookie.length > 0) {
var begin = document.cookie.indexOf("TCPID=");
if (begin != -1) {
var end = document.cookie.indexOf(";", begin+6);
if (end == -1) end = document.cookie.length;
var fupd=UPD(unescape(document.cookie.substring(begin+6, end))).split("-");
if(fupd[0]=="OK") {
for(var i=1 ; i<fupd.length ; i+=2) {
var elm=document.getElementByID("I"+fupd[i]);
elm.setAttribute("src", "/theclub/cgi-bin/personalimage.cgi?UID="+fupd[i]);
if(fupd[i+1].toString()!=="OFF") { document.getElementById("T"+fupd[i]).innerHTML=fupd[i+1]; }
}
}
}
else { window.top.location.href="/theclub/login.htm?MOD=NEW"; }
}
}
function UPD(cvl) {
try {
UPR.open("GET", "/theclub/cgi-bin/chkpubupd.cgi?CVL="+cvl, false);
UPR.setRequestHeader("Content-type", "text/x-www-form-urlencoded");
UPR.send('');
if (UPR.status == 200) { return UPR.responseText; }
else { alert("Error: "+UPR.status+" >> "+UPR.responseText); return ""; }
}
catch (e) { alert("Error in updating system"); return ""; }
}
function PWR(cvl) {
try {
SMR.open("GET", "/theclub/cgi-bin/getmessages.cgi?CVL="+cvl, false);
SMR.send('');
if (SMR.status == 200 && SMR.responseText!=="") { alert(SMR.responseText);}
else if(SMR.status != 200) { alert(SMR.status+" >> "+SMR.responseText); }
}
catch (e) { alert("Error receiving messages"); }
}
function Listener() {
if (document.cookie.length > 0) {
var begin = document.cookie.indexOf("TCPID=");
if (begin != -1) {
var end = document.cookie.indexOf(";", begin+6);
if (end == -1) end = document.cookie.length;
PWR(unescape(document.cookie.substring(begin+6, end)));
}
else { window.top.location.href="/theclub/login.htm?MOD=NEW"; }
}
}
...
</script>
Upvotes: 1
Views: 127
Reputation: 2118
jQuery is not very big. If you include jQuery using this tag:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script>
then it will be cached. Since a lot of websites use this method the file will already be cached on the client's machine if they have been to any site that uses this method. This page explains why this method is useful:
http://encosia.com/3-reasons-why-you-should-let-google-host-jquery-for-you/
You should use jQuery because it works, it does the cross browser compatibility correctly for you and it makes everything easier. There are also lighter weight libraries that do AJAX but you shouldn't do AJAX without a library.
Upvotes: 1