lundi 25 avril 2016

Retrieving data from ajax call in controller

I have an ajax call that is sending some IDs to one of my controllers.

The jQuery that is running to do this is basically searching for elements that have an ID like notification-id- and then grabbing the IDs and storing them in a JavaScript variable.

When I alert() or console.log() this variable it prints out values like 1,2 for two notifications that I have on the page notification-id-1 and notification-id-2.

For my ajax call, I am simply doing the below:

$.ajax({
  url: "",
  method: "POST",
  data: notifications, // Let jQuery handle packing the data for you
  success: function(response) {
       // The data was sent successfully and the server has responded (may have failed server side)
   alert(notifications);
  },
  error: function(xhr, textStatus, errorThrown) {
      // AJAX (sending data) failed
  },
  complete: function() {
      // Runs at the end (after success or error) and always runs
  }
});

I'm trying to test what my controller is receiving by doing dd($request->all()); however that is just returning:

array:1 [
  "undefined" => ""
]

(The ajax call does run successfully)

How can I retrieve the ID values that are being sent in this ajax call inside my controller?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire