function commentFormSubmit(e) { e.preventDefault(); var nick = $('#comment-nick').val(); var email = $('#comment-email').val(); var content = $('#comment-content').val(); var commentType = $('#comment-type').val(); var commentId = $('#comment-id').val(); if (!nick) { alert('Nie podano autora komentarza!'); return; } if (!content) { alert('Nie można wysłać pustego komentarza!'); return; } var formData = { 'comment-nick': nick, 'comment-email': email, 'comment-content': content, 'comment-type': commentType, 'comment-id': commentId, 'mode': 'json' }; $.ajax({ dataType: 'json', type: 'POST', data: formData, url: scriptUrlPrefix+'sendcomment.php', success: commentSubmitDone, error: commentSubmitFailed, }); } function commentSubmitFailed(data) { alert('Nie udało się przesłać komentarza do serwera.'); } function commentSubmitDone(data) { if (data.result == 'OK') { alert('Dodano komentarz'); refreshComments(); } else { alert('Nie udało się dodać komentarza! Komunikat od serwera: ' + data.error); } } function refreshComments() { var commentType = $('#comment-type').val(); var commentId = $('#comment-id').val(); $('#comments').text('Wczytywanie komentarzy...'); var formData = { 'type': commentType, 'id': commentId, }; $.ajax({ dataType: 'html', type: 'GET', data: formData, url: scriptUrlPrefix+'getcomments.php', success: function(data) { $('#comments').html(data); }, }); } function commentsImageReplace(image) { $('#comment-id').val(image.id); } $(document).ready(function() { $('#comment-form').on('submit', commentFormSubmit); });