Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 21st, 2009, 04:24 PM
Registered User
 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Object Expected Error

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

Last edited by bccliff; July 21st, 2009 at 05:47 PM.. Reason: added code
 
Old July 22nd, 2009, 11:16 AM
Registered User
 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Further Investigation with CartPHP.js

I am trying to run the example in chapter 3 of "Beginning Ajax" by Ullman and Dykes.

I am using the PHP version and WampServer.

When I make the change to CartPHP.js as described on page 87 for the function AddRemoveItem I get an error that 'num' is not defined.

When I use the aspx version on page 77, nothing at all happens when I click on the "Add to Shopping Cart" link? No error, just nothing

Is there a browser setting in IE8 and/or Mozilla that could be the problem?

Thanks for looking at this as I would like to use the example with my AJAX class in the fall?

Cliff Sherrill
Yavapai College, CS dept
Prescott, Arizona
 
Old July 23rd, 2009, 12:19 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Where is XDomainRequest defined?
__________________
Joe
http://joe.fawcett.name/
 
Old July 24th, 2009, 10:59 AM
Registered User
 
Join Date: May 2008
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Defining XMLHttpRequest object

It's just above function getData()
 
Old July 25th, 2009, 03:37 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That seems to be where it's called, not where it's defined.
Somewhere in your code should be something like:
Code:
function XDomainRequest()
{
  // implementation here
}
__________________
Joe
http://joe.fawcett.name/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting Object Expected error on mouseover event nrlahoti ASP.NET 2.0 Professional 10 March 15th, 2008 11:30 AM
Object expected error hericles Javascript How-To 1 July 19th, 2007 10:21 AM
error on page: object expected eggoose Javascript 5 April 19th, 2006 02:14 AM
run time error: Object expected shoakat Classic ASP Databases 5 September 22nd, 2004 03:17 PM
object expected shoakat Classic ASP Databases 3 September 20th, 2004 08:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.