<?php
require_once "../class.pAjax.php";
function something1() { return func_get_args(); }
function something2() { return pg_connect("dbname=database user=username password=password"); }
$AJAX = new pAjax;
$AJAX->disableDomainProtection();
$AJAX->enableExportProtection();
$AJAX->export("something1", "something2");
$AJAX->handleRequest();
?>
<!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>Complex Structure Example 2</title>
<?php pAjax::showJavaScript(".."); ?>
</head>
<body>
<h1>Complex Structure 2 Example plus Error Handler</h1>
<p>Call something1 or something2 on server. If ?call=1, it will call something1 (default is no argument sent). If ?call=2, it will test the parser error</p>
<script type="text/javascript">
function Test() {
pAjax.call(this);
pAjax.setDebugMode(true);
// If you call something2, you'll experience an JS error with the following description:
// "Unknown PHP type while parsing [Resource id #XX], type resource"
var req = this.prepare("something<?=((isset($_GET['call'])) ? $_GET['call'] : 1)?>", pAjaxRequest.POST);
// If you need to execute the item in another page, remove the handleRequest
// and add it in the URI set. All data will be sent to the selected page
// req.setURI("algo.php");
req.setParam("teste", Array("valoãr1", "valéor", Array("vaülor3", "valo'r4")));
req.setParam("dataAtual", new Date());
req.setParam("testeStruct", {teste: 0, w2: {item0: 9, item1: 10.98, boolTest: true}, a: "testa\"ndo comprimento de caracteres e vendo como eles se comportam quando a quantidade excede o limite designado pelo script. Será que já alcançamos 100 chars?"});
req.sync();
}
var _p = Test.prototype = new pAjax;
_p.onLoad = function () {
var o = this.getResponse();
// Array example
alert("Item[0]: " + o[0][0] + "\nItem[1]: " + o[0][1] + "\nItem[2][0]: " + o[0][2][0] + "\nItem[2][1]: " + o[0][2][1]);
// Date Time example
alert("DateTime: " + o[1]);
// Struct example
alert("TESTE: " + o[2].teste + "\nW2.Item0: " + o[2].w2.item0 + "\nW2.Item1: " + o[2].w2.item1 + "\nW2.boolTest: " + o[2].w2.boolTest + "\nA: " + o[2].a);
}
</script>
<input type="button" onclick="new Test()" value="Click me!" />
</body>
</html>
|