473,387 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2368
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: prettysmurfed | last post by:
Hi all I have a bit of a problem, the subject of this post is almost selfexplaing. But here goes: Heres an example of the code I want to implement, its all nice and simple, but the flaw is I...
6
by: Eric Entressangle | last post by:
Hi all, is there any trouble setting an C++ static class method as callback function for a C program or library ? Thanks
2
by: Chris Morley | last post by:
Hi, I have always done my C++ class callbacks with the age old 'using this pointer in parameter of the class's static callback function' and typecasting it to get the specific instance. However...
3
by: ThinkRS232 | last post by:
I have a Win32 DLL that has a standard _stdcall (WINAPI) exports. I am able to call these fine from C#. One call in particular however has a callback to a CDECL function. How would I set that up?...
5
by: DevarajA | last post by:
Is it possible to write a function that, once called, is executed together with the caller without stopping it? I've seen such functions in windows programming, using CALLBACK qualifier before the...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
7
by: David | last post by:
i think i just realized i'm an idiot. again. (not syntactically correct code... just pieces to illustrate) class StateObject { members like socket, receiveBuffer, receiveBufferSize,...
0
by: alon111 | last post by:
sorry for my poor english... ok i tryed you build small server just for learning causes. i used BeginAccept & EndAccept. the problem was that while i was debuging i noticed that only 1 user...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.