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
| Function name | Server PHP | Client Javascript |
Description |
| AJAXLINK | ![]() |
![]() |
Namespace |
| linkDebug | ![]() |
![]() |
Is debugging enabled? |
| linkProxy | ![]() |
![]() |
Page to send requests |
| linkData | ![]() |
![]() |
Cross server variable array |
| linkClientData | ![]() |
![]() |
Temporary client array on server |
| linkParseXml | ![]() |
![]() |
|
| linkSendRequest | ![]() |
![]() |
Send request to proxy |
| linkEncodeXml | ![]() |
![]() |
|
| linkGotRequest | ![]() |
![]() |
|
| linkDecodeXml | ![]() |
![]() |
|
| linkEncodeArray | ![]() |
![]() |
|
| linkSetProxy | ![]() |
![]() |
Set proxy php page |
| linkSetDebug | ![]() |
![]() |
Set debuging mode |
| linkHideDebug | ![]() |
![]() |
Hide debug window |
| debugWrite | ![]() |
![]() |
Write to debug window |
| link_onload | ![]() |
![]() |
called when link has loaded |
| link_onresponse | ![]() |
![]() |
called when link got reply from server |
| isLinked | ![]() |
![]() |
checks if page is initial load or from linkSendRequest |
(functions without links or a description arn't expected to be used)
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]
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]
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;
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";
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"];
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. */
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
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);
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();
JAVASCRIPT ONLY
Exists but disable on server side, writes $html to the debug window on the client side.
Javascript: $AjaxLink.debugWrite("Hello world");
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.
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.
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
?>