Added support do do a push-state ajax request with forms

This commit is contained in:
markusfluer
2017-09-18 14:13:39 +02:00
parent 109e78347f
commit 86e5a2281a
10 changed files with 214 additions and 14 deletions

View File

@@ -1,4 +1,7 @@
module.exports = function(location, callback) {
module.exports = function(location, options, callback) {
options = options || {};
var requestMethod = options.requestMethod || "GET";
var requestPayload = options.requestPayloadString || null;
var request = new XMLHttpRequest()
request.onreadystatechange = function() {
@@ -17,8 +20,16 @@ module.exports = function(location, callback) {
location += (!/[?&]/.test(location) ? "?" : "&") + new Date().getTime()
}
request.open("GET", location, true)
request.open(requestMethod.toUpperCase(), location, true)
request.setRequestHeader("X-Requested-With", "XMLHttpRequest")
request.send(null)
// Add the request payload if available
if (options.requestPayloadString != undefined && options.requestPayloadString != "") {
// Send the proper header information along with the request
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}
request.send(requestPayload)
return request
}