Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- undefined
- test
- manual test
- test
- undefined
- manual test
- test
- function getFreshComments(tabIDToUpdate){
- var tabInnerComments = $("#" + tabIDToUpdate + " .theNote");
- var output;
- $.getJSON("/notesapi/" + tabIDToUpdate, showCommentsGotten);
- function showCommentsGotten(dataFedIn){ //dataFedIn is passed in from the $.getJson function above
- $.each(dataFedIn.todoMessages, (key, item)=>{
- output += item + "<br>";
- });
- var normalComments = output;
- var newComments = normalComments.split(",").join("<br>");
- tabInnerComments.html(newComments);
- }
- }
- $('body').on("submit", ".additionalCommentsForTodo", function(evt){
- evt.preventDefault();
- var tabIDToUpdate = $(this).parent().parent().attr("id");
- var commentToInsert = $(".todoCommentBox", this).val();
- console.log(commentToInsert);
- if(commentToInsert !=""){
- // var commentToInsert = $(".todoCommentBox", this);
- console.log("//~~~~~~~FRONTEND NOTE: the ID number for the update is[" + tabIDToUpdate + "] and the message is: " + commentToInsert);
- $.ajax({
- type : "PUT",
- url : "/notesapi/" + tabIDToUpdate,
- contentType : "application/json; charset=utf-8",
- data : JSON.stringify({
- todoMessages : commentToInsert
- }),
- success : function(){
- setTimeout(function(){
- getFreshComments(tabIDToUpdate);
- }, 2000)
- },
- error : function(XMLHttpRequest, textStatus, errorThrown) {
- if (XMLHttpRequest.readyState == 4) {
- console.log("HTTP error (can be checked by XMLHttpRequest.status and XMLHttpRequest.statusText");
- }
- else if (XMLHttpRequest.readyState == 0) {
- console.log("Network error (i.e. connection refused, access denied due to CORS, etc.");
- }
- else {
- console.log("something weird is happening");
- }
- }
- }); //ajax end
- }
- });
- app.put("/notesapi/:tabID", (request, response) => {
- //mongoose.connect(databaseLoc);
- var idNum = request.params.tabID;
- var newIdNumber = idNum.trim();
- //~~~~~~~~These are the default params for findOneAndUpdate commented out below
- //Model.findOneAndUpdate([conditions], [update], [options], [callback])
- NotesModel.update({_id:newIdNumber},{$push : { todoMessages : request.body.todoMessages } }, (error,data)=>{
- if(error){
- console.log("error in deleting yo!");
- throw error;
- } else {
- console.log("//~~~~~~~BACKEND NOTE: data has been UPDATED ~~~//");
- //mongoose.connection.close();
- //response.status(204);
- response.json(data);
- console.log("//~~~~~~~BACKEND NOTE(2): the ID number for the update is[ --> " + newIdNumber + " <-- ]");
- console.log("//~~~~~~~BACKEND NOTE(3): the message to upload is[" + request.body.todoMessages +"]");
- }
- });
- });
Add Comment
Please, Sign In to add comment