Akshay Wani
Akshay Wani

Reputation: 33

Jquery,AJAX not posting data

I am facing problem while sendingsome arrays and data to a page but it is not getting posted i tried print_r($_POST); but its showing Array() as output and other data is also not being posted

The script is as follows:

<script type="text/javascript">

$(document).on('click', "#submitr", function(){

           var favorite = [];
           var tag = [];
           var type = [];
           var scheme = [];

           $.each($("input[name='pcheck']:checked"), function(){
               favorite.push($(this).val());
           });

           $.each($("input[name='tag[]']"), function(){
               tag.push($(this).val());
           });

           $.each($("input[name='type[]']"), function(){
               type.push($(this).val());
           });

           $.each($("input[name='scheme[]']"), function(){
               scheme.push($(this).val());
           });
           var count=$("#count").val();
           $.ajax({
           type: "POST",
           url: 'reportr.php',
           data: {
           count:count,
           pcheck:favorite,
           tag : tag ,
           type : type,
           scheme : scheme

           },
           success: function() {
    window.location.href = "reportr.php";     }
           });

       });



</script>

On alert the values are being displayed

Upvotes: 1

Views: 263

Answers (1)

jeroen
jeroen

Reputation: 91792

Are you sure about that? Note that you are making 2 requests to reportr.php, first a POST request and when that is successful, a GET request - the redirect. You only show the results of the second requests and $_POST will be empty there.

To see the actual output of your POST request, you need to change the success function:

success: function(data) {
    console.log(data);  
    // window.location.href = "reportr.php";   
}

Now you will see the output of reportr.php in the browser's developer tools console.

Upvotes: 1

Related Questions