I am using PJAX and it is working great for simple examples, but I need to be able to do a few advanced things with the PJAX requests.
I have the following...
var people = [{ first: "John", last: "Doe" }, { first: "Jane", last: "Smith" }];
$("a.sheet-link").pjax("#content");
$('#content').on('pjax:beforeSend', function (e, jqXHR, settings) {
// Modify ajax request here?
// Would like to append the people array to data
// Would like to POST rather than GET
// May need to change content-type to "application/json".
});
I have tried a variety of approaches...
All attempts give me various issues.
I am not sure why this is so difficult. Any help would be greatly appreciated!
Since the documentation points out:
You can also just call $.pjax directly. It acts much like $.ajax, even returning the same thing and accepting the same options.
I would try the following:
var people = [{ first: "John", last: "Doe" }, { first: "Jane", last: "Smith" }];
$('a.sheetlink').click(function(e) {
e.preventDefault();
$.pjax({
type: 'POST',
url: $(this).href,
container: '#content',
data: people,
dataType: 'application/json'
})
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With