| Constructor | Description |
| PHPLiveX($functions, $url) |
Starts to handle ajax requests. Exports php functions for ajax. $functions: Optional. Takes function names (if more than 1, seperated by commas); $url: Optional. The URL of the file in use. When complex URLs are used, the class might not read them itself. It is solved by using this property. |
| Method | Description |
| Export("functionNames,...") | Exports the functions for ajax. Can only be called over run method. Parameter Value: 1) Function names (if more than 1, seperated by commas). 2) "ALL" for all user defined functions. |
ExportObjectMethods("objectName-> methodName,...") |
Exports object methods for ajax. Can only be called over run method.
Parameter Value: objectName (like myObject in "$myObject = new myClass();"). methodName is name of the object method (if more than 1, seperated by commas). |
| ExportMethods("objectNames,...") | Exports all methods of the classes for ajax. Can only be called over run method.
Parameter Value: Object names (if more than 1, seperated by commas); |
| Run() | Creates javascript codes to handle ajax requests. Must be called |
| Property | Description |
| ExternalJS (boolean) | Default is "false". With "true" value, java script codes automatically created by the library are included in with another file. In this case, the user do not see the most of phplivex codes in source. |
<?
function myFunction($text){
return $text;
}
$plx = new PHPLiveX("myFunction");
### OR
$plx = new PHPLiveX();
$plx->Export("myFunction");
?>
<?
class myClass(){
var $Text;
public function __construct($text){
$this->Text = $text;
}
public function setText(){
return $this->Text;
}
}
$test = myClass("it's very easy-to-use");
$plx->ExportObjectMethods("test->setText");
### OR
$plx->ExportObjects("test");
?>
<script language="javascript"><? $plx->Run(); ?></script>
| Parameter | Description |
| type | Can take only one value "r". If you want to get returned value of the function (e.g. pass the value to a variable). And if this parameter is used, the others except "mehod" and "url" cannot be used. Note that if this parameter is used, the ajax request runs synchronously. (During the process, no other function runs and it is slower.) |
| target | Takes the ID value of a DOM element and returned value of the function is printed to its attribute which is defined by "targetProperty". If this parameter is used as "target=alert", the returned value is alerted. |
| mode | The default value is "rw"(rewrite) which means rewriting the returned value to an attribute(defined by "targetProperty") of the "target". If you use
"aw" (append), the value is appended to the initial value of attribute, whereas |
| preload | Can take the ID value of a DOM element used for preload. It must be hidden(style= "visibility:hidden" or "display:none") initially. During the process, the foregoing element is made visible and then hidden when the process finishes. Note that this parameter can not be used with type together, because it needs an asynchronous request. |
| method | Can take "post" and "get" values. These are the http-methods of the xmlhttp request. Default value is "POST". When used with "SubmitForm" method, it becomes the form method. |
| onRequest | The value must be a javascript function. This function runs just before the request is sent. |
| onFinish | The value must be javascript function. This function runs when the response of request is taken, but before it is written to page. In addition, the response code is passed as an argument to the function. If it returns something, the response code to be written is replaced with this returned value. |
| onUpdate | The value must be a javascript function. This function runs when the response of request is taken, but after it is written to page. In addition, the response code is passed as an argument to the function. |
| Can take boolean values (Default is "false"). "true" value means that during the preloading, the content of target dom element is emptied. | interval | Can take a time interval in milliseconds. With this interval, the function is called repeatedly. |
| This parameter, which gives users the possibility to create their own preloading, was deprecated, because the same operation may be done with "onRequest" and "onUpdate" parameters. | |
| targetProperty | By default, "innerHTML" or "value" attributes (which is supported) of the target dom element are manipulated. "targetProperty" can change the attribute manipulated (e.g. by using targetProperty: "style.backgroundColor", the background color of target dom element can be changed). |
| It is "visibility" or "display" attribute (used for hiding and revealing element) of the dom element for preloading. Default is "display". | |
| url | It can be used for three different functions:
|
| Methods | Description |
| ExternalCall(parameters) | Used to send ajax requests to another page. (e.g. new PHPLiveX().ExternalCall({preload: '...', target: '...', url: 'test.php', ...})) |
| SubmitForm(form, filterFunction(default is null), parameters) | Used to send forms by ajax request. The first argument is a form element. The second is a function for filtering (e.g. error controls. Default is null) form values and called before sending form. (e.g. <form onsubmit="return new PHPLiveX().SubmitForm(this, null, {url:'test.php', target: 'alert', method: 'get', ...});">). |
<a href="
javascript:myFunction('it is an example', {target: "showText", preload: "loadSpan"});
">test it</a>
<span id="showText"></span>
<span id="loadSpan" style="display:none;">Loading...</span>
<!--
If you use "visibility" attribute instead of "display", hideProperty parameter must take "visibility"
value.
-->
<script>
function changeResponse(resp){
return "This text is added to returned value of myFunction. " + resp;
}
function showContent(resp){
alert(document.getElementById("showText").innerHTML);
}
</script>
<a href="javascript:
myFunction('It is another example',
{target: "showText", preload: "loadSpan", onFinish: changeResponse,
onUpdate: showContent});">test it</a>
<script language="javascript" >
var output = test__setText("an example", {type: "r"});
# ...
</script>
<a href="javascript:new PHPLiveX().ExternalCall({url: 'test.php', preload: '...', target: '...', ...});">
click to send an ajax request to "test.php" and retreive the page output if exists.
</a>
<form onsubmit="
return new PHPLiveX().SubmitForm(this, null, {url: 'test2.php', method: 'get', onFinish: '...', ...});
">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit">
</form>