(function ($) { "use strict"; $("#addBlogPost").on("submit", function (event) { event.preventDefault(); var category_id = $("#category_id").val(); var category_sub_id = $("#category_sub_id").val(); var blog_header_image = $("#blog_header_image")[0].files[0]; var blog_read_time = $("#blog_read_time").val(); var blog_title = $("#blog_title").val(); var developer_id = $("#developer_id").val(); var blog_details_content = $("#blog_details_content").val(); if (category_id == "" || category_sub_id == "" || blog_header_image == "" || blog_read_time == "" || blog_title == "" || developer_id == "" || blog_details_content == "") { formError(); submitMSG(false, "Did you fill up the form properly?"); } else { event.preventDefault(); submitForm(); // window.location.reload(); } }); function submitForm() { var blog_header_image = $('#blog_header_image')[0].files[0]; var category_id = $("#category_id").val(); var category_sub_id = $("#category_sub_id").val(); var blog_read_time = $("#blog_read_time").val(); var blog_title = $("#blog_title").val(); var developer_id = $("#developer_id").val(); var blog_details_content = $(".ck-editor__editable_inline").html(); var blog_ref_id = $("#blog_ref_id").val(); var blog_data = new FormData(); blog_data.append('api_type', "Add"); blog_data.append('blog_header_image', blog_header_image); blog_data.append('category_id', category_id); blog_data.append('category_sub_id', category_sub_id); blog_data.append('blog_read_time', blog_read_time); blog_data.append('blog_title', blog_title); blog_data.append('developer_id', developer_id); blog_data.append('blog_details_content', blog_details_content); blog_data.append('blog_ref_id', blog_ref_id); $.ajax({ type: "POST", dataType: 'text', cache: false, contentType: false, processData: false, url: "./api/add_blog_data.php", data: blog_data, //"api_type=Add&blog_header_image=" + blog_header_image + "&category_id=" + category_id + "&category_sub_id=" + category_sub_id + "&blog_read_time=" + blog_read_time + "&blog_title=" + blog_title + "&developer_id=" + developer_id + "&blog_details_content=" + blog_details_content + "&blog_ref_id=" + blog_ref_id, success: function (text) { let data = JSON.stringify(text) console.log('data========', data); if (data.status == 200) { formSuccess(blog_ref_id); // setTimeout(() => { // window.location.reload(); // }, 1000); } else { formError(); submitMSG(false, text); } } }); } function formSuccess(blog_ref_id = null) { $("#addBlogPost")[0].reset(); submitMSG(true, blog_ref_id ? "Blog Post Updated!" : "Blog Added!") } function formError() { $("#addBlogPost").removeClass().addClass('shake animated').one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function () { $(this).removeClass(); }); } function submitMSG(valid, msg) { if (valid) { var msgClasses = "h4 tada animated text-success text-center"; } else { var msgClasses = "h4 text-danger text-center"; } $("#msgSubmit").removeClass().addClass(msgClasses).text(msg); } }(jQuery));