简体   繁体   中英

jQuery AJAX POST request: empty in server

Im sending this AJAX request, but in the server the array is empty. Any help? In Firebug I can see the request is being sent.

  $.ajax({
    type: 'POST',
    url: 'presupuesto_guardar.php',
    data: { 'data': '1' },
  })

//PHP
var_dump($_POST); //this is empty

The request is being sent:

在此处输入图片说明

在此处输入图片说明

have you write success function to return response if not then please do as below code

$.ajax({
    type: 'POST',
    url: 'presupuesto_guardar.php',
    data: { 'data': '1' },
    success : function(response){
        console.log(response);
    }
})

Please try php://input to get your post data instead of $_POST

php://input will return all the raw data after header

$post = file_get_contents('php://input');

echo json_encode($post);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM