Public Methods And Variables In PHP


Public Methods And Variables In JavaScript


PHP Usage
PHPLiveX __constructor ( array $functions )
Constructs the class and optionally may apply "Ajaxify" method to specified functions.
$ajax = new PHPLiveX(array("myFunction"))
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)
void AjaxifyAll ()
Applies "Ajaxify" method to all user defined functions in the page.
$ajax->AjaxifyAll()
void AjaxifyObjectMethods ( array $methods )
Applies "Ajaxify" method to specified object methods. PHP 'session' must be started before.
$myObject = new myClass()
$ajax->Ajaxify(array("myObject" => "myMethod", "myObject2" => "myMethod2", ...))
OR $ajax->Ajaxify(array("myObject" => array("method1", "method2", ...)))
Call From JavaScript: myObject.myMethod(arg1, arg2, ..., object options)
void AjaxifyObjects ( array $objects )
Applies "ajaxify" method to each method of the specified objects. PHP 'session' must be started before.
$myObject = new myClass()
$ajax->Ajaxify(array("myObject", "myObject2", ...))
Call From JavaScript: myObject.anyMethod(arg1, arg2, ..., object options)
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 Encoding = "UTF-8"
The charset encoding of the ajax response. It must be the same as page encoding.
$ajax->Encoding = "ISO-8859-1"
void Run ( bool $includeJS = true, string $filepath = "phplivex.js" )
Creates some javascript codes to handle your ajax requests or includes them via "phplivex.js". Must be called after the "AJAXIFY" methods.
$ajax->Run(true)


JS Usage
void ExternalRequest ( object options )
Sends an ajax request to any page specified by url parameter.
new PHPLiveX().ExternalRequest({"url": "target.php", params: [param1, param2]})
bool SubmitForm ( 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
new PHPLiveX().SubmitForm("myForm", {"method": "get", "target": "alert"})
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>
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>
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><br>
<script type="text/javascript">
myFunction({"target": "testArea", "mode": "aw"})
</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>
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>
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>
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 } })
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})
int interval = null
A time interval (milliseconds), the function is continuously called in.
myFunction({"target": "testArea", "interval": 10000})
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"}})
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 "ExternalCall" and "SubmitForm" methods
event onCreate = null
Invoked as soon as the xmlhttp connection is opened.
myFunction({ "onCreate": function(xmlhttp){ //Do something } })
event onUninitialized = null
Invoked before the connection is opened. (xmlhttp status is 0)
myFunction({ "onUninitialized": function(xmlhttp){ //Do something } })
event onLoading = null
Invoked before the xmlhttp request is sent. (xmlhttp status is 1)
myFunction({ "onLoading": function(xmlhttp){ //Do something } })
event onRequest = null
Invoked while the xmlhttp request is processing (xmlhttp status is 2). Headers and status are available.
myFunction({ "onRequest": function(xmlhttp){ //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(xmlhttp){ //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.
myFunction({ "onFinish": function(response, xmlhttp){ //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, xmlhttp){ //Do something } })
event onFailure = null
Invoked when an exception is caught during the request.
myFunction({ "onFailure": function(error){ //Do something } })