Created
September 6, 2012 22:00
-
-
Save marcmartino/3660692 to your computer and use it in GitHub Desktop.
this issue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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