TIA:
I am using Beginning Ajax book by Ullman and Dykes.
Doing the example in chapter3 using PHP. In the file cartPHP.
js I continue to get a "Object Expected" error on the line.
xHRObject.open("GET", "managecart.php?action=" + action + "&book=" + book + encodeURIcomponent(book) + "&value=" + Number(new Date), true);
The code "up top" in creating the XMLHttpRequest seems good. I am using IE8 wonder if there is another way to create xHRObject now?
var xHRObject = false;
/*
if (window.XMLHttpRequest)
{
xHRObject = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
xHRObject = new ActiveXObject("Microsoft.XMLHTTP");
}
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
for (var i=0; i<activexmodes.length; i++){
try{
xHRObject = new ActiveXObject(activexmodes[i])
}
catch(e){
//suppress error
}
}
}
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
xHRObject = new XMLHttpRequest()
*/
xHRObject = new XDomainRequest();
function getData()
{
if ((xHRObject.readyState == 4) &&(xHRObject.status == 200))
{
var serverResponse = xHRObject.responseXML;
var header = serverResponse.getElementsByTagName("book");
var spantag = document.getElementById("cart");
spantag.innerHTML = "";
for (i=0; i<header.length; i++)
{
if (window.ActiveXObject)
{
spantag.innerHTML += " " +header[0].firstChild.text;
spantag.innerHTML += " " + header[0].lastChild.text + " " + "<a href='#' onclick='AddRemoveItem(\"Remove\");'>Remove Item</a>";
}
else
{
spantag.innerHTML += " " +header[0].firstChild.textContent;
spantag.innerHTML += " " + header[0].lastChild.textContent + " " + "<a href='#' onclick='AddRemoveItem(\"Remove\");'>Remove Item</a>";
}
}
}
}
function AddRemoveItem(action)
{
var book = document.getElementById("book").innerHTML;
if(action=="Add")
{
xHRObject.open("GET", "managecart.php?action=" + action + "&book=" + book + encodeURIcomponent(book) + "&value=" + Number(new Date), true);
}
xHRObject.onreadystatechange = getData;
xHRObject.send(null);
}
As you can see, I have tried several things to make sure the XHRObject object is indeed created, all to no avail.
Thanks,
Cliff