Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax validation issue
    primarykey
    data
    text
    <p>I'm validating and posting form data via ajax with code below. </p> <p>The problem is, it doesn't break posting if during validation occured an error. Here is my code</p> <pre><code>var autoSaveInterval = null; var counter = 0; function call() { postViaAjax(true) } function postViaAjax(autosaveMode) { var name = $("#name").val(); var title = $("#title").val(); var menu = $("#menu").val(); var parentcheck = $(".parentcheck:checked").val(); var id = $("#id").val(); var author_id = $("#author_id").val(); if (parentcheck == 0) { var parent = parentcheck; } else { var parent = $("#parent").val(); } var content = CKEDITOR.instances['content'].getData(); content = encodeURIComponent(content); var dataString = 'name=' + name + '&amp;title=' + title + '&amp;menu=' + menu + '&amp;parentcheck=' + parentcheck + '&amp;id=' + id + '&amp;parent=' + parent + '&amp;content=' + content + '&amp;author_id=' + author_id; $.ajax({ type: "POST", url: "processor/dbadd.php", data: dataString, dataType: "json", success: function (result, status, xResponse) { var message = result.msg; var err = result.err; var now = new Date(); if (message != null) { if (autosaveMode) { $('#submit_btn').attr({ 'value': 'Yadda saxlanıldı ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() }); } else { $.notifyBar({ cls: "success", html: message + ' ' + now.getHours() + ':' + now.getMinutes() + ':' + now.getSeconds() }); } } if (err != null) { $.notifyBar({ cls: "error", html: err }); } } }); }; function validate() { var name = $("#name").val(); if (name == "") { $.notifyBar({ cls: "error", html: "Səhifənin qısa adını daxil edin" }); return false; } var title = $("#title").val(); if (title == "") { $.notifyBar({ cls: "error", html: "Səhifənin geniş adını daxil edin" }); return false; } var menu = $("#menu").val(); if (menu == "") { $.notifyBar({ cls: "error", html: "Səhifə harada yerləşəcək? Mütləq birini seçin" }); return false; } var parentcheck = $(".parentcheck:checked").val(); var parent = $("#parent").val(); if (!$(".parentcheck").is(":checked")) { $.notifyBar({ cls: "error", html: "Ayrıca yoxsa hansısa başlıq altında? Mütləq birini seçin" }); return false; } else if (parentcheck == '1') { if (parent == '0') { $.notifyBar({ cls: "error", html: " Parent səhifəni seçin" }); return false; } } return true; } $(document).ready(function () { $('.autosave').hide(); $("#add_form").submit(function (e) { if (counter === 0) { if (validate()) { $('.autosave').show(); counter++; } } postViaAjax(false) e.preventDefault(); }); $('#autosave').click(function () { if ($(this).is(':checked')) { if (autoSaveInterval) { clearInterval(autoSaveInterval); } autoSaveInterval = window.setInterval(call, 5000); } else { $('#submit_btn').attr({ 'value': 'Yadda saxla' }); if (autoSaveInterval) { clearInterval(autoSaveInterval); autoSaveInterval = null; } } }); }); </code></pre> <p>How to fix that problem? I want to show only message and break posting</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload