0

I have a php file Filter page.php, where I am making the ajax call and also writing the logic The alert on success shows the correct data but when I am trying to echo the same in php, it is showing nothing

<html>

<body>
<?php


if(isset($_POST['grpNm'])){
  echo $_POST['grpNm'];
  var_dump($_POST['grpNm']);

}

?>
<script src="jquery-3.6.0.min.js"></script>
 <script>
    $(document).ready(function(){

     var GrpNm="ABC";
     $.ajax({
         type: "POST",
         url: "FilterPage.php",
         data: {grpNm : GrpNm},
         success: function(data){ 
           alert(data);
                  },
         error: function(data){ 
           alert("No"); 
                  },
                  
                });
        });

</script>

</body>
</html>
uddipana
  • 188
  • 2
  • 19
  • What do you mean by "it is showing nothing"? Did you check the output? Also, why do you dump AJAX related output in the middle of the other HTML markup? – Nico Haase Feb 23 '22 at 07:05
  • As I have kept the echo statement in if clause, so the variable is not getting set and echo statement doesn't work and gives no output whereas while I alert the data in ajax success call, it is showing the data correctly. And do we need to separate the ajax call from html ?? I am doing the same and it was working before – uddipana Feb 23 '22 at 07:18
  • If it was working before, what did you change? – Nico Haase Feb 23 '22 at 07:20
  • The same type of code I did few years back and in different machine .and it was working and I am doing same ajax call and posting in php but not working.. – uddipana Feb 23 '22 at 07:23
  • If you are using the **same** code, and sometimes it's working, and sometimes it's not, you need to check why this is happening. For example, have a look at your browser's network console to see whether the request is sent as expected. – Nico Haase Feb 23 '22 at 07:36
  • Yes the request is going, it is showing in network. – uddipana Feb 23 '22 at 07:38
  • Then go on debugging. Does the request contain all data as expected? Does the response look like the one you would expect? – Nico Haase Feb 23 '22 at 07:43

0 Answers0