Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > Synchronuos server callback in a standard way
User Name
Password
REGISTER NOW! Mark Forums Read




Reply Bookmark and Share
1 16th November 04:45
grant wagner
External User
 
Posts: 1
Default Synchronuos server callback in a standard way



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 <gwagner@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
  Reply With Quote


 


Reply


Thread Tools
Display Modes


Some other forums that might be of your interest : Development, Ada, Apple script, Assembler, Awk, Beos, Basic, C, C++, C#, C# .net, .net, .net frameworks, Asp .net, Clarion, Clipper, Clos, Clu, Cobol, Coldfusion, Delphi, Dylan, Eiffel, Forth, Fortran, Haskell, Hermes, Icon, Idl, Java, Java script, Jscript .net, Jcl, Linoleum, Lisp, Lotus, Limbo, Logo, Ml, Mumps, Oberon, Postscript, Pop, Pl1, Prolog, Python, Ruby, Pascal, Perl, Php, Rebol, Rexx, Sed, Sather, Scheme, Smalltalk, Tcl, Vhdl, Vrml, Visual basic, Visual basic .net, Yorick, Mysql, Omnis, Postgresql, Xbase, Access, Oracle, Adabas, Berkeley, Btrieve, Filemaker, Gupta, Db2, Informix, Ingres, Mssql server, Object, Olap, Paradox, Rdb, Revelation, Sybase, Theory, Dbase, Html, Java script, Css, Flash, Photoshop, Corel script, Xml, Tech, Beos, Gem, Hp48, Hpux, Linux, Mac, Ms-dos, Os2, Palm, Solaris, Ti99, Windows, Xenix, Aos, Chorus, Geos, Inferno, Lantastic, Lynx, Mach, Minix, Netware, Os9, Parix, Plan9, Psos, Qnx, Xinu, Sco, Unix, Aix, Aux, 386bsd, Bsdi, Freebsd, Netbsd, Openbsd, Ultrix, Amd, Intel, Aptiva, Buz, Deals, Homebuilt, Overclocking, Programming, Extra forums


Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666