Hello everyone) What I have: Link:

<a href="" title="" onclick="document.dir.folder.value = '<? echo $value?>'; listdir();"><?php echo $value; ?></a> 

Js:

 function listdir(){ xhttp = new XMLHttpRequest(); xhttp.open('POST', 'App.php', true); xhttp.send("folder="+document.getElementById('folder').value); xhttp.onreadystatechange = function() { if (xhttp.readyState != 4) { return; } if (xhttp.status == 200) { console.log(xhttp.responseText); }else{ console.log(xhttp.responseText); } } } 

When you click on a link, the folder field is hidden from the user and the js is transmitted. Everything is transmitted correctly. Further, via Ajax to the server, a banal check:

 if(isset($_POST['folder'])): echo "Okay"; else: echo 'No'; endif; 

Data is not transferred to the server. What is the problem? In JS is not very strong)

    2 answers 2

    Try to set the title as in this question.

     http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); 
    • Setting the header helped. Very grateful) - Vladislav

    Try using something like this (as far as I remember this is used in yii2):

      public function isAjax() { return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest'; }