I am currently attempting to call a PHP file using the GetXmlHttpObject object and so far, I have had some progress. However, it seems that there is an issue with the URL variable.
Do I need to handle the URL string in a different way?
Here is the relevant code snippet:
remoteCounter('marks');//invoking function
document.write("<div id=\"marks\"></div>");//destination div
function GetXmlHttpObject () {
var xmlHttp = null;
try {
// Firefox, Opera 8.0+, Safari, IE 7+
xmlHttp = new XMLHttpRequest();
} catch (e) {
// Internet Explorer - old IE - prior to version 7
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
function remoteCounter(param){
counterObj = GetXmlHttpObject();
var url="HTTP://dnsname/directory/view.php?" + param;
alert(url + " " + counterObj);
counterObj.open("GET", url , true);
counterObj.onreadystatechange=updateCounter;
counterObj.send(null);
}
function updateCounter(){
//alert('updateCounter');
if (counterObj.readyState == 4 || counterObj.readyState == "complete"){
document.getElementById("marks").innerHTML=counterObj.responseText;
}
}
I can substitute the counterObj.responseText variable in document.getElementById("marks").innerHTML=counterObj.responseText;
and observe the test string displaying correctly in the source document, indicating that the HTML and JavaScript source code are not the root of the problem.
I have even opted to comment out sections of the view.php file to simply echo a basic string, yet it does not appear either--leading me to believe the issue lies within the request to the file rather than the contents of the file or the source code.
The actual server name and directory have been replaced with 'dnsname/directory' for this post, and I have included alerts for debugging purposes.
Thank you for your assistance.