Not sure, but Zepto AJAX may be incomplete
by deanpeters
HTML
<script src="http://zeptojs.com/zepto.js"></script>
<script src="http://www.mcclatchyinteractive.com/static/scripts/deferred.min.js"></script>
<div id="main"> </div>
JavaScript
if(window.Zepto) {
Deferred.installInto(Zepto);
console.log("Zepto Deferred Plugin loaded");
}
base = {};
base.options = {};
base.options.debugMode = 0;
function getByAjax(siteName, sectionID) {
/* todo: other ajax parms to consider:
* timeout
* type (post for basic auth?)
* username
* password
*/
var url = getURL(siteName, sectionID);
return $.ajax({
dataType: 'json',
crossDomain: true,
xhrFields: {
withCredentials: true
},
url: url,
success: function(data, textStatus, xhr) {
if(siteName.toLowerCase() == "all")
if(base.options.debugMode > 0) console.log('success: getByAjax(url, data, textStatus, xhr)', url, data, textStatus, xhr);
},
error: function(xhr, errorText, errorThrown) {
console.warn('ERROR: getByAjax(url, xhr, errorText, errorThrown)', url, xhr, errorText, errorThrown);
}
});
}
function getData(siteName, sectionID) {
var dataObj = { "site": {}, "section" : {}, "items" : [] };
$.when(getByAjax(siteName, sectionID))
.then( function(data, textStatus, jqXHR) {
if(textStatus == "success" || textStatus == "OK") {
// data.query.results.json
if (siteName.toLowerCase() == "all" ) {
dataObj.section = {"desc": "Find living stories and articles from all our Carolina Papers", "id": "100", "name": "Top Stories" },
dataObj.site = { "id": "topstories", "name": "Top Stories" },
$.each(data.query.results.json, function(index, value) {
dataObj.items.push(value.items)
});
} else {
dataObj = data
}
// console.log("Ajax SUCCESS (siteName, textStatus, jqXHR, dataObj) ", siteName, textStatus, jqXHR, dataObj);
console.log("Ajax SUCCESS (siteName, dataObj) ", siteName, dataObj); ...