123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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);
- });
|