2017-09-18 14:13:39 +02:00
|
|
|
module.exports = function(location, options, callback) {
|
|
|
|
|
options = options || {};
|
|
|
|
|
var requestMethod = options.requestMethod || "GET";
|
|
|
|
|
var requestPayload = options.requestPayloadString || null;
|
2014-05-04 08:45:22 +02:00
|
|
|
var request = new XMLHttpRequest()
|
|
|
|
|
|
|
|
|
|
request.onreadystatechange = function() {
|
|
|
|
|
if (request.readyState === 4) {
|
|
|
|
|
if (request.status === 200) {
|
|
|
|
|
callback(request.responseText, request)
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
callback(null, request)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-27 21:46:14 -07:00
|
|
|
// Add a timestamp as part of the query string if cache busting is enabled
|
|
|
|
|
if (this.options.cacheBust) {
|
|
|
|
|
location += (!/[?&]/.test(location) ? "?" : "&") + new Date().getTime()
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-18 14:13:39 +02:00
|
|
|
request.open(requestMethod.toUpperCase(), location, true)
|
2014-05-04 08:45:22 +02:00
|
|
|
request.setRequestHeader("X-Requested-With", "XMLHttpRequest")
|
2017-12-19 07:56:30 -05:00
|
|
|
request.setRequestHeader("X-PJAX", "true")
|
2017-09-18 14:13:39 +02:00
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
|
2014-05-04 08:45:22 +02:00
|
|
|
return request
|
|
|
|
|
}
|