-
May 15th, 2007, 12:02 PM
#1
'callback' is undefined
I set up a simple website using ajax framework. The code of html page is as below:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Getting XML with ReadXmlWithGet</title>
<script type="text/javascript" src="ajaxframework.js" />
<script type="text/javascript" >
function callback(xml)
{
xmlData = xml.getElementByTagName("data");
document.getElementById("targetDiv").innerHTML = xmlData(0).firstChild.data;
}
</script>
</head>
<body>
<h1>Getting XML with ReadXmlWithGet
</h1>
<form>
<input onclick="readXmlWithGet('data.xml', callback)" type="button" value="Display Msg 1" />
</form>
<div id="targetDiv" height="100" width="100">The fetched data will appear here.
</div>
</body>
</html>
When I click button after running from Visual Studio 2005, I get error called "callback is undefined."
I am new to this. Anybody could tell me why?
-
May 15th, 2007, 12:13 PM
#2
Re: 'callback' is undefined
Put the function callback above the reference to ajaxframework.js. If that doesn't work, then can you please post the source to that JS file so we can see more.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 15th, 2007, 12:42 PM
#3
Re: 'callback' is undefined
Originally Posted by PeejAvery
Put the function callback above the reference to ajaxframework.js. If that doesn't work, then can you please post the source to that JS file so we can see more.
Thank you for your reply.
I put the reference under and got blank page. The code of ajaxframework.js is as below:
Code:
function readXmlWithGet(urlToCall, functionToCallback)
{
var XMLHttpRequestObj = false;
if (window.XMLHttpRequest)
{
XMLHttpRequestObj = new XMLHttpRequest();
}
else if (window.ActiveObject)
{
XMLHttpRequestObj = new ActiveObject('Microsoft.XMLHTTP');
}
if (XMLHttpRequestObj)
{
XMLHttpRequestObj.open('GET', urlToCall);
XMLHttpRequestObj.onreadystatechange = function()
{
if (XMLHttpRequestObj.readyState == 4 && XMLHttpRequestObj.status == 200)
{
functionToCallback(XMLHttpRequestObj.responseXML);
delete XMLHttpRequestObj;
XMLHttpRequestObj = null;
}
}
XMLHttpRequestObj.send(null);
}
}
-
May 15th, 2007, 01:33 PM
#4
Re: 'callback' is undefined
I see it now. <script> must have an end tag not an end slash. This would also explain the blank page when you changed them around. It would recognize the following text as part of the script and not HTML. Change...
Code:
<script type="text/javascript" src="ajaxframework.js" />
To...
Code:
<script type="text/javascript" src="ajaxframework.js"></script>
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 15th, 2007, 01:52 PM
#5
Re: 'callback' is undefined
Thanks, PeejAvery.
I have another question, which is how I can debug javascript in Visual Studio 2005. I set breakpoint but IDE says that this breakpoint will not currently be hit.
Anybody else can tell me why?
-
May 15th, 2007, 02:26 PM
#6
Re: 'callback' is undefined
Well, I personally like the Error Console in Firefox. I don't work much with Visual Studio 2005. To debug in that, you need to do a multi-step process.
1. Open Control Panel.
2. Open Internet Options.
3. Select the Advanced tab.
4. Uncheck both boxes that say "Disable script debugging".
5. Go to Visual Studio 2005.
6. Click on the Debug menu.
7. Select Windows.
8. Choose Script Explorer. (CTRL-ALT-N)
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|