Skip to content

Instantly share code, notes, and snippets.

@marcmartino
Created September 6, 2012 22:00
Show Gist options
  • Save marcmartino/3660692 to your computer and use it in GitHub Desktop.
Save marcmartino/3660692 to your computer and use it in GitHub Desktop.
this issue
var notes = Object.create(udemObj);
notes.noteArray = [];
notes.template = '<div class="allNotesContainer">' +
'<% _.each(noteArray, function (noteRef){ %>' +
'<%= noteRef.toHtml() %>' +
'<% }) %></div>';
notes.load = function (ajaxPath){
$.ajax({
url: ajaxPath,
type: "GET",
success: ajaxSuccess(this.setData, function (msg){console.log(msg);})
});
};
notes.setData = function (objList){
var noteLiteral, newNote;
console.log(this);
for (var m = objList.length - 1; m >= 0; m--) {
newNote = Object.create(note);
newNote.set(objList[m]);
newNote.arrayNum = this.noteArray.length;
this.noteArray.push(newNote);
}
console.log(this.noteArray);
};
function ajaxSuccess(successFunction, errorFunction){
//generic function for handling ajax returns in the pattern of
//{status: "success" || "failture", "message": data}
return function (data){
var parsedJson, success = false;
try{
parsedJson = JSON.parse(data.responseText ? data.responseText : data);
if (parsedJson.status == "success"){
console.log("success");
success = true;
//successFunction(parsedJson.message);
}
else{
console.warn("request error: " + parsedJson.message);
//errorFunction(parsedJson);
}
}
catch(exceptObject){
console.warn("returned invalid json");
console.log(data);
console.error(exceptObject);
}
if (success){
successFunction(parsedJson.message);
}
else{
errorFunction(parsedJson);
}
};
}
var myNotes = Object.create(notes),
otherNotes = Object.create(notes);
(function getOtherNotes(){
otherNotes.load("ajax/getNotes.php");
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment