trying to make a page which will recursively call a function until a limit has been reached and then to stop. It uses an ajax query to call an external script (which just echo’s “done” for now) howver with neither onSuccess or onFailure triggering i’m finding it hard to find the problem.
Here is the javascript for it. In the header for the webpage there is a script to an ajax.js document which contains the request data. I know the ajax.js works as I’ve used it on another website
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>National Lettings Inventories</title>
<link type="text/css" href="/inv/default.css" rel="stylesheet" />
<script type="text/javascript" src="/inv/includes/swfobject.js"></script>
<script type="text/javascript" src="/inv/includes/ajax.js"></script>
<script type="text/javascript">
swfobject.registerObject("myFlashContent", "9.0.0");
</script>
</head>
<body onload="start()">
<div id="topBar">
<div class="logo">
</div>
</div>
<div id="Body">
<script type="text/javascript">
<!--
var rooms = 1;
var items = 0;
var ccode = "9999/1";
var x = 0;
function echo(string,start){
var ajaxDisplay = document.getElementById('ajaxDiv');
if(start)
{ajaxDisplay.innerHTML = string;}
else
{ajaxDisplay.innerHTML = ajaxDisplay.innerHTML + string;}
}
function locations()
{
echo("Uploading location "+x+" of " + rooms,true);
Ajax.Request("Perform/location.php",
{
method:'get',
parameters: {ccode: ccode, x: x},
onSuccess: function(reply)
{alert("worked");
if(x<rooms)
{
x++;
locations();
}
else
{
x=0;
echo("Done",true);
}
},
onFailure: function()
{alert("not worked");
echo("not done");
}
});
alert("boo");
}
function start()
{locations();}
//-->
</script>
Uploading
<div id='ajaxDiv'>
</div>
</div>
<div class="link" id="bottom">
<a href="index.php" ><img src="/inv/images/back.gif" class="link" alt="BACK"/></a>
</div>
<div id="bottomBar">
<p>Copyright © 2010 National Lettings Inventories</p>
</div>
</body>
</html>
Opera Error Console
JavaScript - http://localhost/inv/Upload/upload.php
Event thread: load
Error:
name: TypeError
message: Statement on line 89: Cannot convert undefined or null to Object
stacktrace: n/a; see opera:config#UserPrefs|Exceptions Have Stacktrace
Any help or advice will be most appreciated.
EDIT: Added the whole page source code, theres no line 89 here though
I don’t notice anything obviously wrong with your code*. But the fact that last alert (after the call) doesn’t fire is a pretty good indicator that the call caused the javascript engine to fail. Have you tried using firebug (or similar) and see what happens on the console?
The onSuccess and onFailure callback will only be called if the call is actually fired. If the script fires an exception, or (since javascript is usually interpreted directly) encounters a syntax error etc. the script engine will usually stop running the script and pop a error message to the javascript console (wich is not allways obviously indicated by the browser). If the script stops before or during the call the callbacks of course won’t fire.
EDIT:
Sounds like you accidentally use an uninitialized variable, somehow. Try double checking that you’ve typed all variables correctly (including case). Not really sure what’s happening as I cannot see what’s on line 89…
EDIT: I just noticed, you’ve written
Ajax.Request(...notnew Ajax.Request(...as in the tutorial on the prototype site. Not sure if it matters, though…(* Though the uppercase letter in the path looks a bit suspicious; not really wrong, but might look like you accidentally uppercased the first letter. Usually best not to require uppercase in url’s in case some browser munges it.)