Make it more compatible with the jQuery PJAX and lets the server choose to optimize the response. Sending the list of selectors would be nice, too.
37 lines
1.1 KiB
JavaScript
37 lines
1.1 KiB
JavaScript
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() {
|
|
if (request.readyState === 4) {
|
|
if (request.status === 200) {
|
|
callback(request.responseText, request)
|
|
}
|
|
else {
|
|
callback(null, request)
|
|
}
|
|
}
|
|
}
|
|
|
|
// Add a timestamp as part of the query string if cache busting is enabled
|
|
if (this.options.cacheBust) {
|
|
location += (!/[?&]/.test(location) ? "?" : "&") + new Date().getTime()
|
|
}
|
|
|
|
request.open(requestMethod.toUpperCase(), location, true)
|
|
request.setRequestHeader("X-Requested-With", "XMLHttpRequest")
|
|
request.setRequestHeader("X-PJAX", "true")
|
|
|
|
// 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
|
|
}
|