AJAX alternatives

They have: 7 posts

Joined: Oct 2009

Recently I thought of creating an indicator a person's forum thread has been updated with a reply (without the need to refresh the page); however, I've been hearing how AJAX may not work the same way for all browsers (even though this could just be because of the code).

I know this may not really be the case, and may in the end boil down to just how compatible the code involved is with different browsers, but I wonder why not use something similar in concept to how CAPTCHA codes can be reloaded with a simple click using JS? Since entire scripts can be run this way without having to refresh the page, why can't there be more alternatives to AJAX in this manner?

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

AJAX programmed properly should work just find on any modern browser that has javacript enabled.

When you hit the reload button on capcha (like the one at http://recaptcha.net/learnmore.html ), it is just AJAX calls back to its server, and gets the information for the javascript on the web page to work with.

-Greg

They have: 7 posts

Joined: Oct 2009

It's not necessary to create an AJAX object in JS to implement captcha relaoding. A simple "imageObj.src='imageaddresshere.php'" suffices to reload it.

I finished implementing it, and it works fine without crashing browsers. You're right about well-coded AJAX though. I just don't know why I still can't fully trust it yet.

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

Well if you just wanted to just be an image to indicate that a new message is there, then you could do the same as capcha then.

I am curious though, If I'm on your site, and I tell it to reload the image used for captcha, and all it is doing is update the image, what are you using when the form submits to tell if I enter it right?

-Greg

They have: 7 posts

Joined: Oct 2009

Instead of refreshing the entire page after you post (to see if there are new posts), you can first test via clicking on the image whether or not new posts have arrived after your post. The image source would naturally be controlled by a script, just like captcha. If the thread updated after you posted, the image changes (and with smart manipulation using javascript and some file comparisons, you can also have the page autoreload accordingly). If not, the image stays the same. Even better, you can have javascript autoreload the image every time interval as well. That way users don't need to click on it to check the thread's status.

The image isn't really going to be used for the form. Either way, since AJAX wasn't involved, the browser-crash headaches won't be invoked either...

Greg K's picture

He has: 2,145 posts

Joined: Nov 2003

The question I was asking about is the one you did for captcha, not the one for the forum updates, as that one would (for it to be functional) does need to be used as part of the form.

They have: 7 posts

Joined: Oct 2009

A captcha code text input definitely needs to be part of the form. Keep in mind that loaded page images alone can not be submitted as part of form data; the captcha image is loaded using a PHP script. The captcha image's script can naturally set the session data (in this case a session variable with the captcha code) to be used for comparison with the form input. The script is executed by simply loading the image. If you reload the image, the script is executed again, and the session variable is reset to a new captcha code value that matches what the new image shows, so there's no problem with reloading.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.