54 lines
1.3 KiB
PHP
Executable File
54 lines
1.3 KiB
PHP
Executable File
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
|
|
require_once __ROOT__.'/autoloader.php';
|
|
|
|
debug();
|
|
|
|
|
|
// DEFAULT SESSION CREDENTIALS
|
|
var_dump( 'SESSID---'.session_id() );
|
|
// var_dump( 'TOKEN----'.( $_SESSION['session_token']==$_COOKIE['session_token'] ? 'YES' : 'NO' ) );
|
|
|
|
|
|
?>
|
|
|
|
<div id=ajax1>NO VALUE</div><br>
|
|
<!-- <div id=ajax2>NO VALUE</div> -->
|
|
|
|
<br><br><br><br>
|
|
|
|
<button id=testAjax>LOAD AJAX</button>
|
|
|
|
<script type='text/javascript'>
|
|
|
|
|
|
function pHandler(data){
|
|
var parsedData = JSON.parse(data);
|
|
|
|
document.getElementById('ajax1').innerHTML = parsedData.data1;
|
|
document.getElementById('ajax2').innerHTML = parsedData.data2;
|
|
}
|
|
|
|
function testAjax(){
|
|
var xhr; // object ajax
|
|
|
|
if(window.XMLHttpRequest) // IE7+, Firefox, Chrome, Opera, Safari
|
|
xhr = new XMLHttpRequest();
|
|
else // IE5, IE6
|
|
xhr = new ActiveXObject('Microsoft.XMLHttpRequest');
|
|
|
|
xhr.onreadystatechange = function(){
|
|
if( xhr.readyState == 4 ) // si la requête est terminée
|
|
if( [0,200].indexOf(xhr.status) > -1 ) // si fichier existe et reçu
|
|
pHandler(xhr.responseText);
|
|
else // si code d'erreur retourne null
|
|
pHandler();
|
|
}
|
|
|
|
xhr.open( 'POST', '/test/ajaxTest.php', true );
|
|
xhr.send();
|
|
}
|
|
|
|
document.getElementById('testAjax').onclick = testAjax;
|
|
|
|
</script>
|