Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* VALIDASI UNTUK FORM TEXTBOX DAN WORK SEPERTI EKSPETASINYA */
- function tombol(){
- var NamaBarang = $('#Txt_Nama').val();
- if(save_method == 'add'){
- url = site + "barang/simpan";
- }else{
- url = site + "barang/update";
- }
- $.ajax({
- url : url,
- type : "POST",
- data : $('#form').serialize(),
- dataType : "JSON",
- success : function(data){
- if (data.success == true) {
- $('.text-message').append('<div class="alert alert-success"><i class="fa fa-check"></i> Data <b>'+ data.result.Txt_Nama +'</b> has been saved</div>');
- $('.form-group').removeClass('has-error')
- .removeClass('has-success');
- $('.help-block').remove();
- $('.alert').delay(500).show(10, function(){
- $(this).delay(3000).hide(10, function(){
- $(this).remove();
- });
- });
- tampil_data();
- pageNormal();
- }else{
- $.each(data.messages, function(key, value){
- var element = $('#'+key);
- element.closest('div.form-group')
- .removeClass('has-success')
- .removeClass('has-error')
- .addClass(value.length > 0 ? 'has-error' : 'has-success')
- .find('.help-block').remove();
- element.after(value);
- });
- }
- },
- error : function (jqXHR, textStatus, errorThrown){
- alert('Error adding / update data');
- }
- });
- }
- /* VALIDASI UNTUK FORM UPLOAD TIDAK WORK */
- /* Bagaimana solusinya? Mohon pencerahannya */
- $(document).ready(function(){
- $('#upload_file').on('submit', function(e){
- e.preventDefault();
- /*if($('#Txt_File').val() == ''){
- alert("Please Select the File");
- }else{*/
- $.ajax({
- url : site + 'upload/aksi_upload',
- method : "POST",
- data : new FormData(this),
- contentType : false,
- cache : false,
- processData : false,
- success : function(data){
- if (data.status == true) {
- $('.text-message').append('<div class="alert alert-success"><i class="fa fa-check"></i> Data <b>'+ data.result.file_name +'</b> has been saved</div>');
- $('.form-group').removeClass('has-error')
- .removeClass('has-success');
- $('.alert').delay(500).show(10, function(){
- $(this).delay(3000).hide(10, function(){
- $(this).remove();
- });
- });
- }else{
- $.each(data.messages, function(key, value){
- /*console.log(key);*/
- var element = $('#'+key);
- element.closest('div.form-group')
- .removeClass('has-success')
- .removeClass('has-error')
- .addClass(value.length > 0 ? 'has-error' : 'has-success')
- .find('.help-block').remove();
- element.after(value);
- });
- }
- }
- });
- // }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement