469,281 Members | 2,486 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,281 developers. It's quick & easy.

Synchronuos server callback in a standard way

User enters an item code to a browser <input type=text> field.
I need to verify the code entered using server callback.

If item code is wrong, user is not allowed to leave the field.
So I think I must use synchronuous server callback for this. Data passed to
server is larger tham 2KB, so POST method should be used.

Unfortunately, W3C standard does not support synchrunuous server callbacks.
It allows using <iframe src=> trick or <script src=> trick by changing src=
attribute dynamically.
Both of them are asynchronous.

IE has Microsoft.XMLHTTP object and Mozilla its clone, XMLHttpRequest()
function. However, those non-standard extensions will not work in other
browsers.

It it possible to make synchronuous server callbacks in a standard way ?

aAndrus.

Jul 20 '05 #1
1 2202
Andrus wrote:
User enters an item code to a browser <input type=text> field.
I need to verify the code entered using server callback.

If item code is wrong, user is not allowed to leave the field.
So I think I must use synchronuous server callback for this. Data passed to
server is larger tham 2KB, so POST method should be used.

Unfortunately, W3C standard does not support synchrunuous server callbacks.
It allows using <iframe src=> trick or <script src=> trick by changing src=
attribute dynamically.
Both of them are asynchronous.

IE has Microsoft.XMLHTTP object and Mozilla its clone, XMLHttpRequest()
function. However, those non-standard extensions will not work in other
browsers.

It it possible to make synchronuous server callbacks in a standard way ?

aAndrus.


It's possible, but it's still dependant on client-side JavaScript being enabled,
and it requires more work on the server.

var serverCallBack = new Image();
serverCallBack.onload = callBackResponse;
serverCallBack.onerror = callBackNoResponse;
function callBackResponse() {
if (this) {
switch (this.width) {
case 1:
// do something
break;
case 2:
// do something else
break;
// etc
}
}
}
function callBackNoResponse() {
alert('Could not validate your input.');
}

Then in your HTML, do something like:

<input type="text" onchange="serverCallBack.src='yourValidator.cgi?da ta=' +
this.value;" />
Now on the server, "yourValidator.cgi" will have to build (or read) and return
content to the browser of Content-type: image/gif (or image/jpeg) with specific
widths for each "response code" you want.

In other words, a gif of width 1 would be for correct input, width 2 would be
for input that's blank, width 3 would be for input that contains incorrect
characters, etc.

By the way, this is still asynchronous, if the user managed to trigger the
onchange event in a second input while the server was still dealing with the
first, it would cause a second asynchronous retrieval of "yourValidator.cgi".
This could cause the onload events for serverCallBack to fire out of order (or
only once for two retrievals). There are ways to avoid that problem as well by
having a "pool" of serverCallBack objects and cycle through them, each with it's
own onload event. If you had say, 10 of them, it's highly unlikely that a human
could cause retrievals fast enough to cause the first one to be used again
before it returned some sort of result.

You've already said that you wanted a more cross-browser solution (ie - one that
didn't use the XML HTTP Request object), so I'm assuming this is for the
Internet? If so, as I've already said, the above functionality would only work
if the user has client-side JavaScript enabled.

Ultimately it might be better to just POST the form and have the server validate
everything at once.

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 6/7 and Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Eric Entressangle | last post: by
2 posts views Thread by Chris Morley | last post: by
3 posts views Thread by ThinkRS232 | last post: by
5 posts views Thread by DevarajA | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.