HTML and CSS Reference
In-Depth Information
12.7 Reviewing the Request API
Even though we didn't walk through setting request headers, I want to show you
the resulting ajax.request after implementing header handling (this is but one
possible solution). The full implementation can be seen in Listing 12.66.
Listing 12.66 The “final” version of tddjs.ajax.request
tddjs.noop = function () {};
(function () {
var ajax = tddjs.namespace("ajax");
if (!ajax.create) {
return;
}
function isSuccess(transport) {
var status = transport.status;
return (status >= 200 && status < 300)
||
status == 304 ||
(tddjs.isLocal() && !status);
}
function requestComplete(options) {
var transport = options.transport;
if (isSuccess(transport)) {
if (typeof options.success == "function") {
options.success(transport);
}
} else {
if (typeof options.failure == "function") {
options.failure(transport);
}
}
}
function setData(options) {
if (options.data) {
options.data = tddjs.util.urlParams(options.data);
if (options.method == "GET") {
var hasParams = options.url.indexOf("?") >= 0;
options.url += hasParams ? "&" : "?";
 
 
Search WWH ::




Custom Search