|
-
Noob Here - Ajax working (kind of)
OK, I am confused. I am working on a website for a small restaurant, and have something that working great, almost. Here's my problem, and I am thinking it's with the Ajax. When the user hovers over a link on the page, I have a scritp that loads text into a div tag (In this case they hover over appetizers link, then the appetizers menu loads into the div tag) My ajax script retrieves the html file for the text and then puts that into to page. This is working but with one problem. Here's some code snippets to help illustrate.
HTML:
<div id="menu">
<a href="#" id="menuOption" name="Appetizers" onmouseover="createMenu('Appetizers')">Appetizers</a>
<a href="#" id="menuOption" name="Sides" onmouseover="createMenu('Sides')">Sides</a>
Javascript:
function createMenu(mnuItem){
switch (mnuItem) {
case "Appetizers":
document.getElementById('menuContent').innerHTML = readItem('Starters.html')
break;
More Javascript (w/ Ajax now):
function readItem(Item){
var menuLocation = "http://"+self.location.hostname+"/Smokey Canyon (rev)/menu/"+Item;
var menuText;
var xRequest;
try {
//FireFox, Safari, Opera 8+
xRequest = new XMLHttpRequest();
} catch (e) {
//Internet Explorer Browsers
try {
xRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
alert("Your browser is too Old");
return false;
}
}
}
xRequest.onreadystatechange = function(){
if(xRequest.readyState == 4){
menuText = xRequest.responseText;
}
}
xRequest.open("GET", menuLocation, true);
xRequest.send(null);
alert(menuText);
return menuText;
}
OK, now I can mention the problem. If I remove that alert(menuText); then I get "undefined" in my div element, with it there, my alert says "undefined" but my page gets what I need.
Does this make any sense? Obviously I want to be able to remove that alert and get the results into my page.
Similar Threads
-
By pradloff in forum Careers
Replies: 0
Last Post: 05-04-2007, 11:20 AM
-
Replies: 1
Last Post: 04-25-2007, 11:39 AM
-
Replies: 0
Last Post: 02-17-2007, 03:36 PM
-
Replies: 1
Last Post: 12-05-2001, 06:12 AM
-
By rahul phatak rahulphatak in forum ASP.NET
Replies: 0
Last Post: 06-01-2000, 05:41 PM
Tags for this Thread
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
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks