Getting $_POST empty in AJAX callback

Solutions

Try something like this:

$.ajax({
   url: Drupal.settings.property_check.base_url + '/search/property-by-address',
   type: 'POST',
   data: {
       'add1':'address line1',
       'add2':'address line2',
       'add3':'address line3'
   },
   headers:{
       'Content-Type': undefined,
   }
}).done(function(response) {
        console.log(response);
})

or

 var address = {'add1':'address line1','add2':'address line2','add3':'address line3'};

 $.ajax({
     url: Drupal.settings.property_check.base_url + '/search/property-by-address',
     type: 'POST',
     data: address,
     headers:{
         'Content-Type': undefined,
     }
 }).done(function(response) {
     console.log(response);
 })
Tags: Routes / Ajax

Similar questions

How can I add a sub-array structure in my results? $_POST
I'm building a form. In that form I have a lot of checkboxes. Normally, It's possible to make an array of some checkboxes (with name attribute). Normally I would have this result with print_r($_POST); I tried to add the name attribute, but the $_POST takes the structure of $form. But how can I add a sub-array structure in my results? This is what I...
How to get $_POST and $_GET parameters
I ajaxly call a route and pass data to it, In my controller, I want to get $_POST['var'] , $_POST['var2'], it seems because of using HttpFoundation in drupal 8, $_POST and $_GET are not exists in old method, How I can access $_POST parameters in custom Controller?
Use $_POST after submit form
I create a form and a page with controller in Drupal 8. I want print value of my example input after submit form. For example my input name is "Tel_number". My code in controller page is: But no resault print.
using $_POST values in form alter to add validation
it's not the first time that i get into trouble using $_post in a node form alter, this time i'd like some assistance. basically, i need to pass some parameters to a form (and i should not pass the appended to the url, as query parameters). but $_POST values don't work as expected (they work until reaching validation phase). So.. in a page i pass a...
D8 | submitForm | Get the $_POST - vars via $form_state or via \Drupal::request()?
On an regular sumbmitForm function, should I fetch the user input via \Drupal::request()->request->get... or is $form_state->getValues(); the better (more saver) way? thx
$_POST undefined from remote server POST
I am writing a Drupal 7 module which is listening for HTTP POST messages to be sent by a 3rd party remote application. For testing I am sending messages using the Firefox Poster extension. If I POST the message, the following code fails to place any value in my local vars (I get 'undefined index'): However, if I send the message using GET, the vars...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.