AJAX does not send POST

Issue

This Content is from Stack Overflow. Question asked by Kingvinst

First of all, I have already read through many other posts and tried different things, but no solution approach has worked so far.

My problem: ajax does not send the POST data.

fillTable.js

function fillTableWithData(htmlID, tableSQL, colsSQL, orderSQL){
  var jsondata = new FormData();
  jsondata.append("action", htmlID);
  jsondata.append("table", tableSQL);
  jsondata.append("cols", colsSQL);
  jsondata.append("order", orderSQL);
  $.ajax({
      url:"table.php",
      method: "POST",
      dataType: 'json',
      contentType:false,
      processData:false,
      data: jsondata,
      success:function(result){
        //   $(htmlID).html(result);
        alert("test");
      }
  });
}

table.php

<?php
  require('db.php');
  echo (count($_POST)); // result is 0
  if(isset($_POST['action'])){ // not set
    if($_POST['action'] == "getDataAsRows"){
      getDataAsRows($_POST['table'], $_POST['cols'], $_POST['order']);
    }
  }  

  function getDataAsRows($table, $cols, $order) {
     ...
  }
?>

Both files are inside the same folder:

/scripts/fillTable.js

/scripts/table.php

The url should not be a problem, since the php code prints out the length of $_POST.



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?