jQuery(document).ready(function () { var commentForm = $(document).find('.comments-form'); var commentSection = $(document).find('.comments').first(); var commentAlert = commentForm.closest('.alert'); //var newMedia; //hide form, show link commentForm.hide(); $(document).find('.comment-add-new').show(); //get template for inserting new comments /* $.ajax({ url: '/media_template.php', method: 'GET', dataType: 'html', success: function (data) { newMedia = data; } }); */ $('body').on('click', '.comment-add-new-sadf', function (e) { e.preventDefault(); alert('asdf'); $('span').stop().css('opacity', 1).text('myName = ' + e.name).fadeIn(30).fadeOut(1000); }); //show comment form above comments section (new comment thread) $('body').on('click', '.comment-add-new', function (e) { e.preventDefault(); //commentForm.hide(1000); //commentSection.before(commentForm); $(this).before(commentForm); commentForm.show('slow'); //$(this).slideUp(); }); //show comment form below selected comment (reply to existing comment) $('body').on('click', '.comment-add-reply', function (e) { e.preventDefault(); var media = $(this).closest('.comment'); commentForm.hide(); media.find('>.comment-body>.comment-text').after(commentForm); commentForm.show('slow'); }); // Attach a submit handler to the form $(commentForm).on('submit', function (event) { event.preventDefault(); // Get some values from elements on the page: //var term = $(this).find( "input[name='s']" ).val(); //var data = $(this).serializeArray(); var data = $(this).serialize(); console.log("Form Data (submit)", JSON.parse(JSON.stringify(data))); //var url = $(this).attr( "action" ); var url = '/nested-comments'; var parentId = 0; if ($(this).parents('.comment').length > 0) { parentId = $(this).closest('.comment').attr('data-Id'); } // Send the data using post //var posting = $.post(url, { parentId: parentId, data: data }, null, 'json'); var posting = $.post(url, data + '&parentID=' + parentId, null, 'json'); //$.post( "test.php", $( "#testform" ).serialize() ); // Put the results in a div posting.done(function (response) { alert('success'); console.log("Response Data (done)", JSON.parse(JSON.stringify(response))); //response = JSON.parse(response); var message = response.status ? response.message : 'Error: ' + response.message; commentForm.after(commentAlert); commentAlert.empty().append(message); if (!response.status) { return; } if (response.status) { var newMedia = `
TEST
"); commentAlert.append("" + status + "
"); commentAlert.append("" + error + "
"); commentAlert.append("" + title + "
"); }); posting.always(function (test) { //alert("finished, be it successful or not"); //test = JSON.parse(test); //test = test.serialize(); //alert(test); }); }); });
{{comment.title}}