logo

zabbey is a small team of web developers who produce user-focused websites and unique internet solutions. Have a look at our portfolio to see what zabbey can offer you.

Zabbey Labs Ajax Protocol

Simple Function Execute Example

00:00


Example Explained:
In the function GetServerTime we tell the zlap library to send data to our PHP file, included is the ID of a <div> element.
The PHP file receives the request, generates the current Time and sends back the Javascript Function to execute and display the time on this page [DisplayServerTime(id,time)]

Simple Javascript Execute Example

00:00


Example Explained:
In the function GetServerTimeX we tell the zlap library to send data to our PHP file, included is the ID of a <div> element.
The PHP file receives the request, generates the current Time and sends back the actual Javascript code to display the time on this page [document.getElementById('server-timeX').innerHTML='June 24, 2006, 8:25:37 pm';]

Auto Send Form
name:
favorite fruit:

Example Explained:
Get's the Form name 'frmTest', loops through all child input tags, if the found input tags have names it adds them to the request, otherwise it skips it. Finally it sends the data to the supplied server file.

More Examples:








Have a look at the examples:

Graphitti Wall


Download:


More
The protocol is simple and really only contains 4 standards: Error, Execute Javascript Function, Execute Javascript Code, Multiple replies' seperator.

A typical reply from our server script would be: 1ExecuteThisFunction()

Zlap checks if the Function exists, if it does it executes it, if not it generates a simple error dialog. (Custom Error functions can be setup)

To execute actual JS code: 2alert('hello world');

Zlap does no error checks and simply executes the code.

The Server could return a custom Error using: 0An error has occured.

Zlap bypasses any code checking and instantly displays an error message. (A custom function can be created for this as well)

Multiple Responses in one line are delimited with <zlap-split>: 1ExecuteFunction()<zlap-split>1ExecuteFunctionA()

This aspect of the protocol, when dealing with user submitted data, needs to be checked within said data. A simple Find and Replace script before sending to the browser should handle it.

Download:
Javascript Zlap Library: zlap.client.js


Functions Explained:

zlapSend(req)
  • Sends a request to the server
  • 'req' is a typical server request
  • Example: zlapSend('phpfile.php?id=select&name=John');
zlapSendA(ids,args,[file optional])
  • Sends a request to the server after building the file and arguments, auto converts args to web freindly text (ie replaces non standard chr's with the hex counterpart).
  • 'ids' an Array populated with first parts of a CGI parameter ('id' in phpfile.php?id=select)
  • 'args' an Array populated with the second part of a CGI parameter ('select' in phpfile.php?id=select)
  • 'file' the file on the server being requested ('phpfile.php' in phpfile.php?id=select)
  • Example: zlapSendA(Array('id','name'),Array('select','John'),'phpfile.php');
  • *The variable zlapServerFile can be set before calling, allowing 'file' to be omitted*
zlapSendForm(frm,[file optional])
  • Sends a request to the server using the names and values of the supplied form, auto converts values to web freindly text (ie replaces non standard chr's with the hex counterpart)
  • 'file' the file on the server being requested ('phpfile.php' in phpfile.php?id=select)
  • Example: zlapSendForm('testForm','phpfile.php');
  • *checks for <input> tags, leave the name field blank to skip*
  • *The variable zlapServerFile can be set before calling, allowing 'file' to be omitted*
zlapReplaceString(sString, sReplaceThis, sWithThis)
  • A simplified Search and Replace functon to avoid the Javascript RegEx Replace method.
  • Example: zlapReplaceString('Hi Frank, this is Ted', 'Frank', 'Bob');
zlapCreateXMLHttp()
  • Creates the HTTPRequest Server Object
zlapCheckError(data)
  • Checks responses from the server for certain errors. PHP Errors are also checked for easier debugging.
zlapResponse()
  • Handles data received from the server
To some using AJAX (and even reusing the code) can be confusing. Zlap is an attempt to create a simple Protocol so the client can communicate with the server in a style that allows the code to be simplified and reused.
(C) Zabbey.com and the Zabbey logo 2006. All Rights Reserved