Javascript

Ajax request

Instead of using jQuery's get,load etc, XMLHttpRequest is available.

var v = document.getElementById("someId").value;
var token = document.getElementsByName('csrf-token').item(0).content;
var xhr = new XMLHttpRequest();
xhr.open("POST", "/path/to/post");
xhr.setRequestHeader('X-CSRF-Token', token);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onloadend = () => {
    if (xhr.status === 200) {
        // Do something.
    } else {
        alert(xhr.status+" "+xhr.statusText+"\n"+new Date().toLocaleString());
    }
};
var params = "model[someField]="+v;
xhr.send(encodeURI(params));