By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,382 Members | 1,637 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,382 IT Pros & Developers. It's quick & easy.

Synchronuos server callback in a standard way

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.