Файл: test.html
Строк: 76
<?php
<!Doctype html>
<html>
<head>
<meta charset="utf-8"/>
</head>
<body>
<p>To run this Test page please put the domAjax folder in your LAMP document root and load this page. You may want to activate developer tools to monitor ajax requests being made</p>
<div id="plain" class="tellme" data-ajax-url="testapi.php" data-ajax-method="post">
The ajax call returned <span style="color:yellow">{{message}}</span>
<div>{{result}} coming home</div>
<div>{{prof.name}}</div>
<div>{{prof.cycle.rad}}</div>
</div>
<br /> <input id="tbox" type="text" class="result" value="" /> <br />
<div id="plain2" data-ajax-url="testapi.php" data-ajax-method="get" data-ajax-params=' { "name":"john", "token":"6ftggvg5"} ' data-ajax-interval="5000.10" data-ajax-callback="handle"></div>
<div id="plain7" data-ajax-url="testapi2.php" data-ajax-method="post" data-ajax-interval="4000.3" data-ajax-callback="handle"></div>
<div id="plain5" data-ajax-config=' {"url":"testapi2.php", "method":"get", "event":"other_dom_id.testevent", "callback":"c.callback", "params":{ "token":"secret" } } '></div>
<div id="plain3" data-ajax-url="testapi.php" data-ajax-method="get" data-ajax-event="testevent" data-ajax-callback="c.callback"></div>
<div id="plain4"></div>
<div id="other_dom_id"></div>
<button onclick="cusEvent()">trigger testevent on div-id="plain3"</button>
<button onclick="cusEvent('other_dom_id')">Trigger testevent on another dom</button>
<script>
var c = {};
c.callback = function(data){
document.getElementById("plain4").innerHTML = data.message;
};
function handle(data, id)
{
document.getElementById("tbox").value = data.message;
}
function cusEvent(id)
{
var event = new Event('testevent');
if(id){ document.getElementById(id).dispatchEvent(event); }
else{document.getElementById("plain3").dispatchEvent(event);}
}
</script>
<script type="text/javascript" src="domAjax.js"></script>
<script>
domAjax([{url:"testapi.php", id:"tep1"},{url:"testapi2.php", id:"tep2"}]);
console.log(domAjax("map"));
</script>
</body>
?>