Documentation (2.6)

PHP Side (PHPLiveX Class)
  • phplivex __constructor ( [ $functions = array() ], [ $options = array("encoding" => "UTF-8") ] )
  • void Ajaxify ( array $functions )
  • void AjaxifyAll ()
  • void AjaxifyObjectMethods ( array $methods, [ bool $ajaxify_vars = false ] )
  • void AjaxifyObjects ( array $objects, [ bool $ajaxify_vars = false ] )
  • void AjaxifyClassMethods ( array $methods, [ bool $ajaxify_vars = false ] )
  • void AjaxifyClasses ( array $classes, [ bool $ajaxify_vars = false ] )
  • void Run ( [ string|bool $js_path = "phplivex.js" ], [ array $plugins ], [ bool $return = false ] )
  • static string Decode ( string $str, string $encoding )


JavaScript Side (PLX Object)
  • bool Submit ( HTMLFormElement|id|name form, object options )
  • void Request ( object options )
  • void LoadCSS ( string path, [object options] )
  • void LoadJS ( string path, [object options] )
  • void Stop ( string id )
  • void AjaxifyUpload ( string|array id, object options )
  • void StopUpload ( string id )


PHP Side (PHPLiveX Class)
PHPLiveX __constructor ( [ $functions = array() ], [ $options = array("encoding" => "UTF-8") ] )
Constructs the class and optionally may apply "Ajaxify" method to specified functions.
$ajax = new PHPLiveX(array("myFunction"))
  • array $functions: names of functions to ajaxify
  • array $options: hold neccesary options. Currently, just an encoding option is available
void Ajaxify ( array $functions )
Gives the possibility to call specified php functions via javascript without refreshing page.
$ajax->Ajaxify(array("myFunction"))
Call From JavaScript: myfunction(arg1, arg2, ..., object options)
  • array $functions: names of functions to ajaxify
void AjaxifyAll ()
Applies "Ajaxify" method to all user defined functions in the page.
$ajax->AjaxifyAll()
void AjaxifyObjectMethods ( array $methods, [ bool $ajaxify_vars = false ] )
Applies "Ajaxify" method to specified object methods. Works for only 'public' methods.
$myObject = new myClass()
$ajax->AjaxifyObectMethods(array("myObject" => array("method1", "method2", ...)))
Call From JavaScript: myObject.myMethod(arg1, arg2, ..., object options)
  • array $methods: names of methods and that of their objects
  • bool $ajaxify_vars: TRUE to ajaxify object properties
void AjaxifyObjects ( array $objects, [ bool $ajaxify_vars = false ] )
Applies "ajaxify" method to each method of the specified objects. Works for only 'public' methods.
$myObject = new myClass()
$ajax->AjaxifyObjects(array("myObject", "myObject2", ...))
Call From JavaScript: myObject.anyMethod(arg1, arg2, ..., object options)
  • array $objects: names of objects to ajaxify
  • bool $ajaxify_vars: TRUE to ajaxify object properties
void AjaxifyClassMethods ( array $methods, [ bool $ajaxify_vars = false ] )
Applies "Ajaxify" method to specified class methods. Works for only 'static' methods.
$ajax->AjaxifyClassMethods(array("myClassName" => array("method1", "method2", ...)))
Call From JavaScript: myClassName.myMethod(arg1, arg2, ..., object options)
  • array $methods: names of methods and that of their classes
  • bool $ajaxify_vars: TRUE to ajaxify class properties
void AjaxifyClasses ( array $classes, [ bool $ajaxify_vars = false ] )
Applies "ajaxify" method to each method of the specified classes. Works for only 'static' methods.
$ajax->AjaxifyClasses(array("myClassName", "myObject2", ...))
Call From JavaScript: myClassName.anyMethod(arg1, arg2, ..., object options)
  • array $classes: names of classes to ajaxify
  • bool $ajaxify_vars: TRUE to ajaxify class properties
void Run ( [ string|bool $js_path = "phplivex.js" ], [ array $plugins ], [ bool $return = false ] )
Creates some javascript codes to handle your ajax requests or includes them via "phplivex.js". Must be called after the "AJAXIFY" methods.
$ajax->Run()
  • string|bool $js_path: phplivex.js file path. FALSE to prevent including the file(to include anywhere else)
  • bool $plugins: file paths of plugins
  • array $return: TRUE to return, instead of printing
static string Decode ( string $str, string $encoding )
Converts an UTF-8 text to specified charset encoding. This is very important for who use ANSI charsets (e.g. iso-8859-x). Because of a character bug in php "json_decode" function, people may need to use this to avoid any trouble in use of some language based characters like "ö", "ş", "ç".
$str = $ajax->Decode($str, "iso-8859-1")
  • string $str: text to decode
  • string $encoding: new charset encoding


JavaScript Side (PLX Object)
void Request ( object options )
Sends an ajax request to any page specified by url parameter.
PLX.Request({"url": "target.php", params: {p1:param1, p2:param2}})
  • object options: object list of options
bool Submit ( HTMLFormElement|id|name form, [object options] )
Submits a form to the specified url with an ajax request. If an action is not defined for the form, url parameter must be the target. AJAX file upload currently is not supported
PLX.Submit("myForm", {"method": "get", "target": "alert"})
  • HTMLFormElement|id|name form: the form to submit
  • object options: object list of options
void LoadCSS ( string path, [object options] )
Loads a css file into the page. May be used to change design of page in one click.
PLX.LoadCSS("design.css")
  • string path: css file path
  • object options: object list of options
void LoadJS ( string path, [object options] )
Loads a js file into the page.
PLX.LoadJS("functions.js")
  • string path: js file path
  • object options: object list of options
void Stop ( string id )
Stops the function which is called repeatedly in defined interval
PLX.Stop("request_id")
  • string id: the id value of the ajax request
void AjaxifyUpload ( string|array id, object parameters )
Provides ajax file upload functionality. Click to see the usage and available parameters.
  • string|array id: id(s) of file inputs
  • object parameters: properties of upload operation.
void StopUpload ( string id )
Stops an upload operation.
PLX.StopUpload("file_input_id")
  • string id: id value of the file input
HTMLDomElement|id target = null
Without an extra code, the response text may be printed to any attribute(target_attr) of a dom element
<div id="testArea"></div>
<script type="text/javascript">myFunction({"target": "testArea"})</script>
HTMLDomElement|id preloader = null
It must be a hidden dom element. The preloader is shown during the request automatically and hidden again when it is done. A dom element can be hidden with two attributes: "display" or "visibility". This may be changed using "preloader_style" parameter.
<div id="preloadDiv" style="visibility:hidden;">Loading...</div>
<script type="text/javascript">
myFunction({"target": "testArea", "preloader": "preloadDiv"})
</script>
string content_type = "text"
It is the content type of the response. If it's json, response will be a json object.
myFunction({"content_type": "json", onFinish: function(response){ //Do Something } })
string mode = "rw"
If the "target" parameter is assigned, "mode" determines the printing type:
"rw": prints the response, erasing the initial content.
"aw": appends the response to end of the initial content
"asw": appends the response to start of the initial content
<div id="testArea"> There are something here... </div>
<script type="text/javascript">
myFunction({"target": "testArea", "mode": "aw"})
</script>
string target_attr = "innerContent"
An attribute of the target dom element. If "target" parameter is assigned, this parameter determine which attribute will be manipulated. "innerContent" symbolizes innerHTML and value. If target is an HTMLInputElement, value is used, otherwise innerHTML ...
<div id="testArea" style="background-image:#FFFFFF"></div>
<script type="text/javascript">
myFunction({"target": "testArea", "target_attr": "style.backgroundColor"})
</script>
HTMLDomElement|id preloader_style = "visibility"
It can be assigned two values: "visibility" and "display". There is one important difference between them. An element with visibility:hidden, takes place in the page whereas the one with display:none, is ignored when browser renders the page.
<div id="preloadDiv" style="display:none;">Loading...</div>
<script type="text/javascript">
myFunction({"preloader": "preloadDiv", "preloader_style": "display"})
</script>
string method = "POST"
The http method of the request. It may be "post" or "get".
myFunction({"method": "GET"})
string type = "asynchronous"
The request type. It may be "asynchronous" or "synchronous". It is not recommended to use "synchronous" as it locks the browser and does not work with some parameters. So, it is better to leave it as it is.
string url = ""
The page url, request is sent to. Used with "ExternalRequest" and "SubmitForm" methods
string id = RANDOM
Defines an id for the ajax request. Default value is randomly created. It's important when used with interval and history
int interval = null
A time interval (milliseconds), the function is continuously called in.
myFunction({"target": "testArea", "interval": 10000})
int timeout = 30000
The time in milliseconds, when the ajax request is aborted. After this time, onTimeout function is called.
myFunction({"timeout": 6000})
object params = {}
Used with "ExternalRequest" method. This parameter is assigned user defined variables and these are sent to specified url.
new PHPLiveX().ExternalRequest({"params": {"email": "blabla@gmail.com", "id": 350}})
object headers = {}
The http request headers.
myFunction({"headers": {"pragma": "no-cache", "content-type": "application/text; charset=UTF-8"}})
bool clear_content = false
If it's true, the content of the target dom element is emptied during the request.
<div id="testArea"> There is something here </div>
<script type="text/javascript">
myFunction({"target": "testArea", "preloader": "preloadDiv", "clear_content": true})
</script>
bool eval_scripts = true
If the response text contains javascript codes, they are appended to the page automatically. If eval_scripts is turned off, they are ignored.
myFunction({"eval_scripts": false})
bool caching = false
TRUE to cache ajax requests with get method.
myFunction({"caching": true, "method": "GET"})
bool history = false
Can be used with Ajax History Plugin.
myFunction({"history": true})
event onPreload = null
Provides the functionality to create your own preloader. "start" function is called just before the request; "complete" function is called at the end.
myFunction({ "onPreload": {start: function(){}, complete: function(){}} })
event onTimeout = null
A function called when ajax request take longer time than timeout.
myFunction({ "timeout": 8000, "onTimeout": function(){ alert("max execution time exceeded"); } })
event onCreate = null
Invoked as soon as the xmlhttp connection is opened.
myFunction({ "onCreate": function(root){ //Do something } })
event onUninitialized = null
Invoked before the connection is opened. (xmlhttp status is 0)
myFunction({ "onUninitialized": function(root){ //Do something } })
event onLoading = null
Invoked before the xmlhttp request is sent. (xmlhttp status is 1)
myFunction({ "onLoading": function(root){ //Do something } })
event onRequest = null
Invoked while the xmlhttp request is processing (xmlhttp status is 2). Headers and status are available.
myFunction({ "onRequest": function(root){ //Do something } })
event onInteraction = null
Invoked when the xmlhttp request is sent and receiving the response (xmlhttp status is 3). The response holds partial data.
myFunction({ "onInteraction": function(root){ //Do something } })
event onFinish = null
Invoked when the request is sent and response is completely received (xmlhttp status is 4). Before this, target parameter does not work. To do that, onUpdate should be used. If this function returns false, target and onUpdate parameters are ignored.
myFunction({ "onFinish": function(response, root){ //Do something } })
event onUpdate = null
The only difference between onFinish and onUpdate events, onUpdate function is triggered after the target parameter. If there is no "target", both will be the same.
myFunction({ "onUpdate": function(response, root){ //Do something } })
event onFailure = null
Invoked when an exception is caught during the request.
myFunction({ "onFailure": function(error){ //Do something } })