<?php
require_once "../class.pAjax.php";
class Holder {
var $sce;
function Holder() {
$this->sce = new SpecialCharExample();
}
}
class SpecialCharExample {
function SpecialCharExample() { }
function getIt($str) {
return array(substr($str, -2, 1), strlen($str));
}
}
$holder = new Holder();
$AJAX = new pAjax;
$AJAX->disableDomainProtection();
$AJAX->enableExportProtection();
$AJAX->export("holder.sce.getIt");
$AJAX->handleRequest("UTF-8"); // Default response charset is UTF-8
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Special Char retriever</title>
<?php $AJAX->showJavaScript(".."); ?>
<script type="text/javascript">
function Converter() {
pAjax.call(this);
pAjax.setDebugMode(true);
}
var _p = Converter.prototype = new pAjax;
_p.convert = function (v) {
// Unlimited sub-objects supported
// In this example:
//
// + holder (class Holder)
// |-+ sce (class SpecialCharExample)
// | |-- getIt (method)
//
// Remember to set the property as public
//
// [TODO] Add support to factory calls. Currently, no factory is supported:
// $holder->getSce()->getIt($str) <<< ERROR!
var oRequest = this.prepare("holder.sce.getIt", pAjaxRequest.POST);
oRequest.setParam("param", v);
oRequest.execute(pAjaxRequest.ASYNC);
}
_p.onLoad = function () {
var data = this.getResponse();
alert("Retrieved text: " + data[0]);
alert("Original length: " + data[1]);
}
</script>
</head>
<body>
<input type="text" name="x" id="x" value="éõàüe" disabled="true" style="width: 50px;">
<input type="button" name="check" value="Get Special Char (ü)"
onclick="(new Converter()).convert(document.getElementById('x').value); return false;">
</body>
</html>
|