Laurent Laurent - 2 months ago 5x
Ajax Question

Getting the JSON result out of an AJAX query

I am struggling to get the result of my AJAX query being sent correctly to my PHP script (gethint2.php). Was just wondering what I'm doing wrong here. Thanks for being tolerant to me, as I am a newbie in AJAX/Javascript :)

If I don't put the condition (if(isset($_POST['controleur'])) ..., it works perfectly well

Here is my query :

function showHint2(pControleur) {
var args = '';
console.log("Coucou show int " + pControleur);
/*var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {

};"GET", "gethint2.php", true);
//args = 'controle='+pControleur;
type: "POST",
url: "gethint2.php",
//data: "{" + args + "}",
data : {controleur: pControleur},
contentType: "application/json; charset=utf-8",
dataType: "json",
success : function(code_html, statut){ // success est toujours en place, bien sûr !


error : function(resultat, statut, erreur){


complete : function(resultat, statut){




My gethint2.php file :

<?php require('common.php');
$result = $db->add_news('titles');


debug your code with add var_dump($_POST); before if(isset($_POST['controleur'])) in your php file, and check the response via your console browser