// nx is a GET request, only for small and fixed datas
nx('engine.php?action=youraction&type='+parseInt(type)+'&id='+parseInt(id)+'&nav='+parseInt(nav)+'&lw='+parseInt(LW()),'engine');
// or
nx("_engine.php?action=json","engine");
// np is a POST request, designed to send huge amout of variable datas
np('newpost.php','action=post&forumid='+parseInt(post[1])+'&titre='+titre+'&msg='+str+'&postid='+parseInt(post[2]),'posting');
function h(){var c=false,g='',d='';c=new XMLHttpRequest();this.r=function(x){d=x};this.appendData=function(a,b){g+=(g.length==0)?a+'='+escape(b):'&'+a+'='+escape(b)};this.s=function(a,b,e){b=b.toUpperCase();c.onreadystatechange=function(){if(c.readyState==4&&c.status==200){if(typeof e=='function'){e(c);return}switch(d){
case'engine':
// an example to grab a JSON block sent by PHP. The callback will land here.
myJSONblock.push(JSON.parse(c.responseText));
return;break;
case'posting':
// for example, you can forward the return of your PHP post template contained into "c.responseText" into a div with getElementById. You can do what you want. The callback will land here.
document.getElementById('yourID').innerHTML = c.responseText;
return;break;
}}};if(b=='GET'){c.open('GET',a);c.send(null)}else if(b=='POST'){c.open('POST',a);c.setRequestHeader('Content-Type','application/x-www-form-urlencoded');c.send(g)}return true};return this}function nx(f,x){var a=new h();a.r(x);a.s(f,'GET');return true};function np(f,a,x){var b=new h();b.r(x);b.appendData(a+'&');b.s(f,'POST');return true};
switch ($_GET['action']){
case "forum": // ** FORUM **
checkLogin ( '2' );
if (!$_SESSION['logged_in']) {
echo SendJSON(array_merge(array("some javascript commands"),htmlTOarray("forum_face.php")));
} else {
ob_start();
eval("?>".file_get_contents("forum_".$forum[(int)$_GET['type']].".php")."");
$feval = ob_get_contents();
ob_end_clean();
echo SendJSON(array_merge(array("some javascript commands"),navbar(),array(" ")));
}
break;
default:
switch ($_POST['action']){
case "posting": // ** POST **
checkLogin ( '2' );
if (!$_SESSION['logged_in']) {
echo SendJSON(array_merge(array("some javascript commands"),htmlTOarray("forum_face.php")));
} else {
if (!(int)$_POST['postid']) $_POST['postid'] = "";
$query = $db->query ( "INSERT INTO dso_forums.posts (`id`, `parent`, `msg_parent`, `reponses`, `vues`, `note`, `auteur`, `titre`, `contenu`, `derniers`, `access`, `password`, `date`) VALUES (NULL, ".$db->qstr ( (int)$_POST['forumid'] ).", ".$db->qstr ( (int)$_POST['postid'] ).", '', '', '10', ".$db->qstr ( $_SESSION['username'] ).", ".$db->qstr ( $_POST['titre'] ).", ".$db->qstr ( $_POST['msg'] ).", '', '', '', '".date('Y-m-d H:i:s')."' )" );
}
break;
default:}
}
?>
function SendJSON($arr) {
return json_encode(array_map("utf8_encode",$arr));
}
?>
Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/nPYaA7RkG1k/12675