I have stopped using jQuery. It feels nice to save 85 kB on each pageload. However I have an ajax problem.
Old jQuery Ajax
This was about what my old jQuery ajax looked like.
$.ajax({
method: "POST",
url: 'ajax',
data: {
data: test
},
success : function(response) {
console.log(response);
}
});
My new ajax call
var request = new XMLHttpRequest();
request.open("POST", "ajax", true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
request.onreadystatechange = function () {
if (request.readyState != 4 || request.status != 200) return;
console.log( request.responseText );
};
request.send('data=test');
1. Request ajax don’t work
This works with jQuery but not with vanilla (plain) javascript.
if( kirby()->request()->ajax() )
Why does the above don’t work with kirby()->request()->ajax()
. The ajax call is working fine without it.
2. Method POST don’t work
Method POST don’t work with vanilla JS. However I can use 'method' => 'ALL'
but I would prefer just POST like before.