'Ajax post:Not able to retrieve posted data in php

I want to post a data using ajax call. The ajax call us working fine but when I am alerting the data, it is showing all the html tags and then I am not able to retrieve the data in php.

My code for file Filterpage.php is as below:

<html>
<body>
<?php
  $data= $_POST['grpNm'];
  echo $data;
?>

<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>

The alert(data) in ajax call is giving all the html tags and in php I am getting the following error: Notice: undefined index:grpNm

Please help me where I am doing wrong.. I have searched many questions and tried the answers but not working



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source