我正在使用PJAX,它适用于简单的示例,但我需要能够使用PJAX请求执行一些高级操作.
我有以下......
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".
});
Run Code Online (Sandbox Code Playgroud)
我尝试了各种方法......
所有尝试都给了我各种问题.
我不知道为什么这么难.任何帮助将不胜感激!
由于文档指出:
您也可以直接调用$ .pjax.它的行为很像$ .ajax,甚至返回相同的东西并接受相同的选项.
我会尝试以下方法:
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'
})
});
Run Code Online (Sandbox Code Playgroud)