Ajax post returns nothing

sohal07


I am trying to send some data with post to a php file but for some reason its not being posted. I receive an empty array in console log from the php file on var_dump.
Here is code I have in these files:

index.php

<button type="button" class="btn btn-warning" id="resetPassword">Reset Password</button>

<script>
  $(document).ready(function (e){
   $("#resetPassword").click(function(e){
      e.preventDefault();
      $.ajax({
        url: "scripts/process.php",
        type: "POST",
        data: {name: 'test'},
        cache: false,
        processData:false,
        success: function(data) {
          if (data === 'Success') {
            new PNotify({
              title: 'Success!!!',
              text: 'Request completed successfully.',
              type: 'success',
              styling: 'bootstrap3'
            });
            $('#exampleModal').modal('hide');
            $('#datatable-buttons').DataTable().ajax.reload();
          } else {
            console.log(data);
            new PNotify({
              title: 'Error!!!',
              text: data,
              type: 'error',
              styling: 'bootstrap3'
            });
            //document.getElementById("status").className += " alert-danger";
            //$("#status").html(data);
          }
        },
        error: function (xhr, ajaxOptions, thrownError) {
          alert("ERROR:" + xhr.responseText+" - "+thrownError);
        } 
      });
    });
  });
</script>

Here is the php file process.php.

var_dump($_POST);

Result in console.log:

array(0) {}

Solution:

Remove processData: false

thanks guys.

Volkan Yılmaz

Remove processData:false, section and then try again.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related