Welcome to weSEO

Login

Welcome back, nice to see you again.

Register - it's free!

Comment, spread your love, communicate

Welcome back!

Nickname:

Password:

Lost your Password?

Create your new Account

Nickname:

Mailadress:

Ajax with webSPELL-Function "fetch"

Fetch Function webSPELL Explained
Ajax is a big topic at the moment. I didn't really get into it because I thought it was very difficult. It might be but webSPELL makes it very easy.

I suggest you Download the Ajax Comments Validator. It will make it easier to understand whats going on.

Now that you've got the Ajax-Validation running, lets take a look at the way it works.

HTML

Everything starts with an input.

I'm going to show you how it works with the Homepage/URL-Input.

Our HTML-Code looks like this: (See templates/comments_add_visitors.html)

As you see I've added a span-Tag after the input - with an ID. However, the more important part is this:
We use the Javascript Event onblur, it calls the function checkhomepage() whenever the User takes the foces off the input.

Javascript

You can find the Javascript in templates/comments_add_visitors.html

Lets break it down.
This just replaces the Content of the span-Tag with the id="validateHomepage" with the /images/ajax-loader.gif-Icon.
As explained in the graphic on top, there are 4 parameter that are necessary.

URL


direct.php will be called, with the parameters:
action=check_url
homepage=the-value-entered-in-the-input

The direct.php will accept this parameters, call the correct PHP-Function and return a String.

ID

"The ID of the Element we want to manipulate" is pretty much all there is to say about this parameter. We want to manipulate the span-Tag with the id "validateHomepage"

ACTION


We've got 4 options here. add, replace, execute and formfield. We want to replace the Content of the span-Tag, with the String the PHP-Script (direct.php) returns.

BASE


time or event, we are using it event-based. As said before we are using an Javascript Event.
If you want to call the fetch-function time-based you've got to add the 5th, optional, parameter - milliseconds.

Lovers

Avatar
eggzy - 07.02.2010 - 17:50
awesome read. I'm trying to learn ajax for a while, but it always seems complicated.

Avatar
Pascalmh - 07.02.2010 - 18:31
Hope I could help. You maybe want to try to make an Ajax-Registration-Validator to try what you just learned :-)

eggzy - 07.02.2010 - 19:49
good idea ^^

also you should change the code style, it's ugly

Avatar
atxx - 13.02.2010 - 22:08
just learn jquery :) it supports ajax

eggzy - 17.02.2010 - 23:27
but why to use js framework for small things like this validation, when ws can do it

eggzy - 20.02.2010 - 18:09
hey what's with function: overlay and overlayclose .
is it lightbox/modal?

Your comment
Name
E-Mail (used for Gravatar)
Homepage
No Avatar
Security Code