Send Flag from PHP to JavaScript

flags, javascript, php

Solution

I found out why my Flag displays Undefined. It is simply that to make a alert (flagQuery) a boolean does not function.

I combine my code with that of Jan Turon, and this is achieved

function getFlagValue() {
    var xmlHttp = new HmlHttpRequest();
    xmlHttp.onload = function() {
        if (xmlHttp.status==200) yourCustomHandler(xmlHttp.responseText);
    };
    xmlHttp.open("GET","getAmazonResult.php",true);
    xmlHttp.send();
}

function yourCustomHandler(response) {
    flagQuery = response;
    alert(flagQuery);
}
flagQuery = getFlagValue();
                    if (flagQuery = true) {
                        alert ("Flag = TRUE");
                    }
                    else {
                        alert ("Flag = FALSE");
                    }

And now I see if the flag is true or false

Problem

I want to initialize a flag in a condition in PHP and send it to be read by JavaScript. At the moment, I have this code : PHP ``` if ($totalResults > MAX_RESULT_ALL_PAGES) { $queryUrl = AMAZON_SEARCH_URL . $searchMonthUrlParam . $searchYearUrlParam . $searchTypeUrlParam . urlencode( $keyword ) . '&page=' . $pageNum; } else { $queryUrl = AMAZON_TOTAL_BOOKS_COUNT . $searchMonthUrlParam . $searchYearUrlParam . $searchTypeUrlParam . urlencode($keyword) . "&page=" . $pageNum; $flagQuery = TRUE; echo $flagQuery; } ``` JavaScript ``` <script> function getFlagValue() { var xmlHttp; if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } else { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState==4 && xmlHttp.status==200) { alert(xmlHttp.responseText); } }; xmlHttp.open("GET","getAmazonResult.php",true); xmlHttp.send(); } var flagQuery = new Boolean(); flagQuery = getFlagValue(); alert(flagQuery); </script> ``` I can't seem to retrieve the Flag in JavaScript.

Original source