featherlight ajax post request

1.2k Views Asked by At

How can I load a Featherlight modal with ajax content by sending POST data in the featherlight request instead of GET?

$.featherlight({
    ajax: 'some.php'
});

The above code will load the content from 'some.php'. What if I want to send along a POST value?

For example with jQuery I would use:

$.ajax({
  method: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
})

That would pass along some POST data. This is what I'm trying to accomplish with featherlight.js. Is this possible?

2

There are 2 best solutions below

0
On

If you look in the featherlight.js file, the method called for the ajax call is load which is like $.get, load can take data, but it was not added in featherlight code as you can see below.

ajax: {
    ...
    var $container = $('<div></div>').load(url, function(response, status){
    ...
},

So, to answer your question, you cannot send post data.

0
On

Old question but, in case someone falls here:

As Johnny suggests and, according to the documentation, Featherlight does not provide any built in functionality for AJAX POST.

You can, however, make your POST request and call featherlight with the response:

$.post(myUrl, myData, function (response) {
    $.featherlight(response, configuration);
}