SMMP/public_html/test/sessionTest.php

54 lines
1.3 KiB
PHP
Raw Normal View History

2016-07-02 15:10:41 +00:00
<?php define('__ROOT__', dirname(dirname(__FILE__)) );
2016-10-18 14:03:03 +00:00
require_once __ROOT__.'/autoloader.php';
2016-07-02 15:10:41 +00:00
debug();
// DEFAULT SESSION CREDENTIALS
var_dump( 'SESSID---'.session_id() );
// var_dump( 'TOKEN----'.( $_SESSION['session_token']==$_COOKIE['session_token'] ? 'YES' : 'NO' ) );
2016-07-02 15:10:41 +00:00
?>
<div id=ajax1>NO VALUE</div><br>
<!-- <div id=ajax2>NO VALUE</div> -->
2016-07-02 15:10:41 +00:00
<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>