• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Simple AJAX Error

jen4950

[H]F Junkie
2FA
Joined
Apr 25, 2001
Messages
12,865
I've got a simple little AJAX snippet that I'm trying to get to work..

http://vacorp.com/Practice/testAjax.htm

And I am getting an error, "Object Expected"

It's a real simple thing I'm sure, but I'm missing it. Any ideas?

testAjax.htm:
Code:
<script type="text/javascript">function ajaxFunction()
{var xmlHttp;
try
  {  // Firefox, Opera 8.0+, Safari  xmlHttp=new XMLHttpRequest();  }
catch (e)
  {  // Internet Explorer  try
    {    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    }
  catch (e)
    {    try
      {      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      }
    catch (e)
      {      alert("Your browser does not support AJAX!");      return false;      }    }  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      document.myForm.time.value=xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET","/Practice/time.asp",true);
  xmlHttp.send(null);  }</script>

<html><body><form name="myForm">
Name: <input type="text" onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form>
</body>
</html>

time.asp:
Code:
<%
response.expires=-1
response.write(time)
%>
 
I'd try putting an id on the form and using document.getElementById instead

edit: u need to debug and figure out WHAT is null...
 
You really need to format your code better. Stop putting comments on the same line as your code. You are commenting out parts of xmlHttp definition and the try statement as well.

Code:
<script type="text/javascript">
function ajaxFunction()
{
	var xmlHttp;
	try{
		xmlHttp=new XMLHttpRequest();  
	}
	catch (e){  
		try {    
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");    
		}
		catch (e) {    
			try { 
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");      
			}
			catch (e) { 
				alert("Your browser does not support AJAX!");      
				return false;
			}    
		}  
	}

	xmlHttp.onreadystatechange=function() {
	    if(xmlHttp.readyState==4) {
	      document.myForm.time.value=xmlHttp.responseText;
	      }
	    }
	xmlHttp.open("GET","time.asp",true);
	xmlHttp.send(null); 
}

</script>
 
I was working with copy-paste code from w3schools- just getting my feet wet-

I'll play with it some more.. got distacted with a Blackberry 'emergency'...

thanks guys
 
I've found the Firebug addon for Firefox to be of great help when tracking down javascript errors. It will let you set breakpoints and step through the code line by line, as well as view the contents of variables, etc..
 
I've found the Firebug addon for Firefox to be of great help when tracking down javascript errors. It will let you set breakpoints and step through the code line by line, as well as view the contents of variables, etc..

ooh ryly? I'll check that out in the morning for sure..
 
If you want to dabble with AJAX, I'd recommend checking out some javascript libraries that abstract out some of the boilerplate code. Some that come to mind would be Prototype, Scriptaculous, YUI, etc.

This would allow you to write code like:

Code:
<script type="text/javascript" src="/js/prototype.js"></script>
<script type="text/javascript">
function update() {
  new Ajax.Updater($('idOfElementToUpdate'), '/time.asp');
}

Using third party libraries also helps you work around or at least rely on someone else more knowledgeable than you to fix annoying cross-browser quirks that seem to plague javascript-related functionality. This is why I highly recommend mature, widely used libraries like Yahoo's YUI because they have fixed/worked around more problems with browser quirks than you could possibly imagine to get their code to a point where it "just works".

Edit: I noticed you're using ASP, if you are able to use the latest ASP.NET they have added some really neat stuff that allows you to do some seamless AJAX by writing .NET code. I haven't personally played with it so I can't vouch for it's cross-browser friendliness but it might be an option you could look into.
 
That YUI library is really impressive; I had no idea it existed. Some really good sources- Thanks a ton!
 
Heh, doing a simple ajax request to get data (from a light weight service that accessed a database, for example) would be as easy as:

Code:
<input type="button" value="Click Me" on="click then r:get.some.data.request" />
<div on="r:get.some.data.response then value[data] and effect[Pulsate]"></div>

Using that framework I mentioned earlier. BTW, it's easy to integrate it with YUI, ExtJS, and it already includes prototype and Scriptaculous (but you could tell that from the effect in the on expression ;)). You could also trigger the message (in this case r:get.some.data.request) without the user having to click on a button. :D
 
Heh, doing a simple ajax request to get data (from a light weight service that accessed a database, for example) would be as easy as:

Code:
<input type="button" value="Click Me" on="click then r:get.some.data.request" />
<div on="r:get.some.data.response then value[data] and effect[Pulsate]"></div>

Using that framework I mentioned earlier. BTW, it's easy to integrate it with YUI, ExtJS, and it already includes prototype and Scriptaculous (but you could tell that from the effect in the on expression ;)). You could also trigger the message (in this case r:get.some.data.request) without the user having to click on a button. :D

The whole concept of AJAX is very compelling- the ability to create a thick app or something like it is really cool- I'm actually working on converting the Payment Calculator that I wrote into an internet app- ends up that a big part of our audience doesn't have Excel.:eek::( So going down this road seems like something that is worth my effort. Unfortunately, can't spend a ton of time on it right now- really busy, but working on it as I can.. bit's and pieces..
 
The whole concept of AJAX is very compelling- the ability to create a thick app or something like it is really cool- I'm actually working on converting the Payment Calculator that I wrote into an internet app- ends up that a big part of our audience doesn't have Excel.:eek::( So going down this road seems like something that is worth my effort. Unfortunately, can't spend a ton of time on it right now- really busy, but working on it as I can.. bit's and pieces..

Sure, I guess I'm saying this'll save you time without your having to learn a ton of stuff and there's already a great community built around it. Good luck, however you decide to build it though :)
 
It might have been prudent of amromousa to explain that he works for Appcelerator, so he has a bit of a vested interest in pushing that over something else. Nothing personal, but I figured I might let you know. I actually have a friend that works there, and work with a bunch of people that are good friends with some devs there as well, so I hope no one takes that as me trying to troll him :)

For getting your feet wet, my thoughts would be while appcelerator is a great framework to use when you already understand what's going on behind the scenes and want things to "just work" to get something up and running quickly, it may not be as friendly for a "learning experience" as walking through some simpler libraries that don't abstract away 99% of the code and don't teach you anything but a proprietary toolset. Put simply, starting with something that is as close to the basics (or that frames the basics in simple terms with good documentation) as possible and then working up is a tried and true learning technique.

P.S. Tell MRobinson and MLuffle "hi" from a fellow Atlanta Startup :)
 
It might have been prudent of amromousa to explain that he works for Appcelerator, so he has a bit of a vested interest in pushing that over something else. Nothing personal, but I figured I might let you know. I actually have a friend that works there, and work with a bunch of people that are good friends with some devs there as well, so I hope no one takes that as me trying to troll him :)

For getting your feet wet, my thoughts would be while appcelerator is a great framework to use when you already understand what's going on behind the scenes and want things to "just work" to get something up and running quickly, it may not be as friendly for a "learning experience" as walking through some simpler libraries that don't abstract away 99% of the code and don't teach you anything but a proprietary toolset. Put simply, starting with something that is as close to the basics (or that frames the basics in simple terms with good documentation) as possible and then working up is a tried and true learning technique.

P.S. Tell MRobinson and MLuffle "hi" from a fellow Atlanta Startup :)

Absolutely true. I suppose it isn't common knowledge here (I've definitely said it in a prior thread though). Apologies for that. Still, I wouldn't recommend it if I thought it wouldn't help given that I'm not paid to post about it anywhere but on our own community network. :) I wouldn't have mentioned it at all in this case (given the OP's first post) if it weren't for the post on YUI. I figured if the OP was going to look at Yahoo!'s library, they might want to take a look at Appcelerator as well. I don't currently own any part of the company so aside from continuing to get a paycheck and thinking it's pretty neat, I don't really have much vested interest (it's true that it's enough to warrant disclosing my employment). My intent certainly wasn't to be pushy but to give an example or another framework.

Edit: MRobinson says hello. Pleased to web-meet you, Z. :)
 
I picked that up- kinda why I was shying away from it, I want to know the basics- I don't need a wrapper around all of this cool stuff- I want to understand how it works fundamentally. But besides that, looks like a cool project- no harm no foul.
 
So, back to the issue at hand.. (At home, drinking a beer- so not much real thought going into it at the moment- was a brutal day..)

I assume my problem is in the Time.asp file. And this kinda coincides with another issue I have with passing variables from a base file to an included file- but that's a seperate issue.

Anyway- gotta go to dinner-
 
Cool; good luck :). Did you ever step through it in firebug to see what the response actually was (better than assuming ;))?
 
nope- not yet, just got back from dinner.. kinda loaded.. will look at it in the morning..
 
Back
Top