I am creating a commercial API for the first time for responsive webpages/web applications (mobile devices).
I am new and, sadly, working alone as well as new to Javascript (long complicated story).
I was just wondering if someone from the industry could offer their professional opinion on the following format of a "get" call:
var getSample = function(params) {
//Returns Object
return $.ajax({
url: URL + 'downloadQuadrat.php',
type: 'GET',
data: { 'projectID': params.pid, 'quadratID': params.qid },
dataType: dataType
});
}
Function call:
var printList = function(lid,options,get) {
var list = $("ul#"+lid);
var promise = get(options);
promise.promise().then(
function(response) {
var items = response;
list.empty();
$.each(items, function(item,details) {
var ul = $('<ul/>');
ul.attr('id', lid+'_'+details.ID);
var li = $('<li/>')
.text(details.ID)
.appendTo(list);
ul.appendTo(list);
$.each(details,function(key,value) {
var li = $('<li/>')
.text(key+': '+value)
.appendTo(ul);
});
});
}
);
}
Any input or guidance will be hugely appreciated.
getSample
supposed to be getting or setting? It seems to do both. \$\endgroup\$get
function is undefined and.promise()
with no params is used for monitoring animations. With your$.ajax()
example, it seems to me you need to at least look at using the.done()
chained method for a start. \$\endgroup\$