promise.php
<?php
// Test various AJAX and Promise calls.
// This uses https://bartonphillips.org/test_examples/examples/uptime.php and
// https://bartonphillips.org/test_examples/examples/query.ajax.php for Ajax calls.
// Load info from mysitemap.json for use by my framework SiteClass.
// Check SiteClass out at https://github.com/bartonlp/site-class.
// It has full documentation at that site.
$_site = require_once(getenv("SITELOADNAME"));
$extra = json_decode(file_get_contents("promise.json"));
foreach($extra as $name=>$value) {
$_site->$name = $value;
};
$S = new SiteClass($_site); // $S gives access to my framework.
// AJAX 'page' == 'form'
if($_POST['page'] == 'form') {
$name = $_POST['username'];
$value = $_POST['id'];
echo "AJAX Form: name=$name, value=$value";
exit();
}
// AJAX 'page' == 'ajax'
if($_POST['page'] == 'ajax') {
$data = $_POST['data'];
echo "AJAX hello World: $data";
exit();
}
// Get this file for display below.
$promiseText = escapeltgt(file_get_contents("promise.php"));
$uptest = escapeltgt(file_get_contents("https://bartonphillips.org/test_examples/examples/uptest.php"));
$query = escapeltgt(file_get_contents("https://bartonphillips.org/test_examples/examples/query.ajax.php"));
// Set up the scripts for my framework
$S->b_script = <<<EOF
<script src="https://bartonphillips.net/js/syntaxhighlighter.js"></script>
<link rel='stylesheet' href="https://bartonphillips.net/css/theme.css">
<script nonce='$S->cspNonce' src="promise.js" defer></script>
EOF;
// Setup the css for my framework
/*
$S->css =<<<EOF
#promise {
display: none;
}
EOF;
*/
// Get the $top and $footer using my framework
[$top, $footer] = $S->getPageTopBottom();
echo <<<EOF
$top
<form id="myform" name="myform" action="promise.php" method="post">
<input type="text" name="username" value="johndoe">
<input type="number" name="id" value="123456">
<input type="submit">
</form>
<button id="send">Get The Time</button>
<div id="startup"></div>
<div id="response"></div>
<hr>
<button id="showpromise">
View the file
<b>promise.php</b>,
<b>query.ajax.php</b> and
<b>uptest.php</b>
</button>
<div id="promise" hidden>
<p>promise.php</p>
<pre class='brush: php'>
$promiseText
</pre>
<p>query.ajax.php</p>
<pre class='brush: php'>
$query
</pre>
<p>uptest.php</p>
<pre class='brush: php'>
$uptest
</pre>
</div>
$footer
EOF;
query.ajax.php
<h1>GO AWAY</h1>
uptest.php
Go Away