Ajax Link Help

Ajax Link is designed to communicate between server and client, after the page is loaded known as Ajax or web 2.0, Ajax Link is small and completly handles communication leaving you more time to build your website. Ajax link contains 2 files AjaxLink.php and AjaxLink.js, both files have a simular set of functions.

http://phpdataweb.com/AjaxLink

Contents

Function name
Server PHP
Client Javascript
Description
AJAXLINK
yes
yes
Namespace
linkDebug
yes
yes
Is debugging enabled?
linkProxy
yes
yes
Page to send requests
linkData
yes
yes
Cross server variable array
linkClientData
yes
no
Temporary client array on server
linkParseXml
no
yes
linkSendRequest
yes
yes
Send request to proxy
linkEncodeXml
yes
yes
linkGotRequest
no
yes
linkDecodeXml
yes
yes
linkEncodeArray
yes
yes
linkSetProxy
yes
yes
Set proxy php page
linkSetDebug
yes
yes
Set debuging mode
linkHideDebug
no
yes
Hide debug window
debugWrite
no
yes
Write to debug window
link_onload
no
yes
called when link has loaded
link_onresponse
no
yes
called when link got reply from server
isLinked
yes
no
checks if page is initial load or from linkSendRequest

(functions without links or a description arn't expected to be used)

AJAXLINK

This is the frameworks name space, in php it is a class module, java it is simply functions within a function.
Both client and server automaticly create an instance of this object known as $AjaxLink, you may use this to access all the other functions.

Javascript: $AjaxLink = new AJAXLINK();
PHP: $AjaxLink = new AJAXLINK();

[Back to contents]

linkDebug

A boolean variable true or false. Returns true if debugging is enabled and the debug window is allowed to become visible.
Use linkSetDebug to change its value.

Javscript: if($AjaxLink.linkDebug){ /* */ }
PHP: if($AjaxLink->linkDebug){ /* */ }

[Back to contents]

linkProxy

String value of the php script filename, think of this as 'method' on a normal <form> tag, its where requests are sent, by default requests are sent to the current php page loaded. Both client and server can set this using linkSetProxy

Javascript: $script = $AjaxLink.linkProxy;
PHP: $script = $AjaxLink->linkProxy;

[Back to contents]

linkData

Shared variable array between php and javascript, both client and server can read and write these values, warning: if client sets a value it is passed to linkClientData on the server. Use linkSendRequest to send the new array after editing.

Javascript: $AjaxLink.linkData["varname"] = "abc";
PHP: $AjaxLink->linkData["varname"] = "abc";

[Back to contents]

linkClientData

PHP SERVER ONLY

For security reasons data coming from Javascript linkData cannot be trusted so it is moved to the temporary linkClientData for the server script to read and pass to the public array. If you want to ignore secure for testing use: (php) $AjaxLink->linkData = $AjaxLink->linkClientData;

PHP: $AjaxLink->linkData["varname"] = $AjaxLink->linkClientData["varname"];

[Back to contents]

linkSendRequest

This has 3 different meanings depending on client or server or initial page load, basicly it sends data from client to server or server to client. Call this whenever you want communication to proceed. Use isLinked() on the server to see if it was called by linkSendRequest.

Javascript: $AjaxLink.linkSendRequest(); // sends a HTTP_REQUEST
PHP: $AjaxLink->linkSendRequest(); /* if isLinked() returns XML file, else return urlencoded XML string. */

[Back to contents]

linkSetProxy

Sets the linkProxy to be called during any communications with linkSendRequest.

Javascript: $AjaxLink.linkSetProxy("index.php");
PHP: $AjaxLink->linkSetProxy("index.php"); // tells javascript to use that page next time

[Back to contents]

linkSetDebug

Sets the linkDebug to enable and disable the debugging window on javascript. If set on the server, the debugging mode will be passed to the client on the next linkSendRequest

Javascript: $AjaxLink.linkSetDebug(true);
PHP: $AjaxLink->linkSetDebug(true);

[Back to contents]

linkHideDebug

JAVASCRIPT ONLY

Hides the debug window on the client, note if linkDebug=true, if will open again when debugWrite is next called. Use linkSetDebug(false) aswell to disable debugging.

Javascript: $AjaxLink.linkHideDebug();

[Back to contents]

debugWrite($html)

JAVASCRIPT ONLY

Exists but disable on server side, writes $html to the debug window on the client side.

Javascript: $AjaxLink.debugWrite("Hello world");

[Back to contents]

link_onload

JAVASCRIPT ONLY

Is called if it exists when link has loaded, write "<script language='javascript'>function link_onload(){ /* */ }</script>" somewhere on your webpage to use this feature.

[Back to contents]

link_onresponse

JAVASCRIPT ONLY

Is called if it exists when link has recieved a response to linkSendRequest, write "<script language='javascript'>function link_onresponse(){ /* */ }</script>" somewhere on your webpage to use this feature.

[Back to contents]

isLinked

PHP ONLY

To make things easies, linked pages may send Ajax requests to the same page as when the page was originaly loaded, use isLinked, to check if you are loading a page for the first time or responding to a request. You should do this at the top of the page and use exit(); after as you cannot write anything to the browser if it is a request.

PHP:

<?php
include("AjaxLink.php");
if($AjaxLink->isLinked()){
$AjaxLink->linkInit();
/* do something here */
$AjaxLink->linkSendRequest();
exit();
}
// normal page load
?>


[Back to contents]