Prototype AJAX call & IE6 - not working

23 views
Skip to first unread message

Jessica Smith

unread,
Nov 8, 2011, 3:36:38 PM11/8/11
to Prototype & script.aculo.us
Hi, I'm a total n00b when it comes to AJAX and Prototype. I do have
an example that works in IE7+, FF and Chrome, but not IE6. I'm
getting the following JS error when I include the function in my test
page. I tried including the XMLHttpRequest section thinking that
might be part of my problem, but it doesn't make a difference. Any
suggestions are welcome.

[error]
Line: 37
Char: 5
Error: Expected identifier, string or number
Code: 0
[/error]

[code]
<html>
<head>
<title>f1</title>
<script type="text/javascript">
if (!window.XMLHttpRequest) {
window.XMLHttpRequest = function() {
return new ActiveXObject('Microsoft.XMLHTTP');
}
}
</script>
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript">
var cdInterval=0;
var cdTime=cdInterval+1;
function changeCart(cartname) {
alert(cartname);
document.getElementById("cartname").innerHTML = cartname;
//setTimeout("ajaxlastcall()",500);
}

function ajaxlastcall() {
url = "http://devmachineurl/sid.htm?
sid=6680&prg=menu&frame=lastcall";
new Ajax.Request(url, {
onSuccess: function(response) {
var data =
response.responseXML.getElementsByTagName( 'LastCallData' );
for( var i = 0; i < data.length; i++ ) {
var interval = data[i].getAttribute( 'interval' ) - 0;
var lastcall = data[i].getAttribute( 'lastcall' );
}
if (interval == 0)
document.getElementById("lct").innerHTML=lastcall;
else startit(interval,lastcall);
},
onException: function(response) {
alert("Failed" + response.responseText);
},
});
}

</script>
</head>
<body>
<div id="cartname">Please select a cart.</div>
<input type="hidden" id="toggleval" name="toggleval" value="yes">
</body>
</html>
[/code]

T.J. Crowder

unread,
Nov 8, 2011, 5:38:49 PM11/8/11
to Prototype & script.aculo.us
Hi,

It would have been really helpful if you'd pointed out which line was
line 37, since things tend to get re-wrapped. :-)

But the problem is here:

>     onException: function(response) {
>         alert("Failed" + response.responseText);
>     },
-------^

That dangling comma at the end of the object literal you're passing
into Ajax.Request. Most JavaScript engines are fine with it, and it's
now even officially supported (there was some ambiguity before the
ECMAScript 5th ed. spec came out a couple of years ago), but older
versions of IE choke on it. Remove the dangling comma and it should
stop complaining. There's a similar problem with dangling commas at
the ends of array literals (e.g., given `var a = [1, 2, 3, ];`, what's
the length of `a`?).

More:
http://blog.niftysnippets.org/2010/09/literal-improvement.html

HTH,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com

Phil Petree

unread,
Nov 8, 2011, 5:42:18 PM11/8/11
to prototype-s...@googlegroups.com

LOL i was sitting here with phone in hand, counting the lines and had just zeroed in on the same line when your answer came in.

--
You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group.
To post to this group, send email to prototype-s...@googlegroups.com.
To unsubscribe from this group, send email to prototype-scripta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.

Jessica Smith

unread,
Nov 8, 2011, 6:04:30 PM11/8/11
to Prototype & script.aculo.us
Thank you both! I finally saw it minutes after I posted....naturally!

Victor

unread,
Nov 9, 2011, 2:39:47 PM11/9/11
to prototype-s...@googlegroups.com
[offtop]
Jessica, do you know about much shorter synonym of document.getElementById()?
[/offtop]
Reply all
Reply to author
Forward
0 new messages