2017-06-09 7 views
0

以下は私のajaxコールコードです。php codeイグナイターajaxコールのスウィートアラート

var date = new Date(); 
yr = date.getFullYear(), 
    month = +date.getMonth() + 1 < 10 ? '0' + parseInt(date.getMonth() + 1) : date.getMonth() + 1, 
    day = +date.getDate() < 10 ? '0' + date.getDate() : date.getDate(), 
    newDate = yr + '-' + month + '-' + day; 
$("#dateupdated").val(newDate); 
var url = "<?php echo base_url("resident/updateresident/{$resident->id }"); ?>" 
$.ajax({ 
    url: url, 
    type: "POST", 
    data: new FormData(this), 
    contentType: false, 
    cache: false, 
    processData: false, 
    success: function (data) { 
     swal("Operation completed successfully."); 
     // var objs = $.parseJSON(data); 
     // var status=objs.status; 
    } 
}); 

これはうまく動作しますが、私は甘い警告の確認ポップアップでそれを囲むと、コントローラにデータを送信しません。誰かがこれを取り除く方法を教えてもらえますか?

新しいコードは次のとおりです。私はあなたがここで確実に動作します以下のコードであり、それがテストされ、間違いを犯しているソリューションを持っ

swal({ 
    title: "Are you sure?", 
    text: "Are you sure that you want to cancel this order?", 
    type: "warning", 
    showCancelButton: true, 
    closeOnConfirm: false, 
    confirmButtonText: "Yes, cancel it!", 
    confirmButtonColor: "#ec6c62" 
}, function() { 
    alert(); 
    var date = new Date(); 
    yr = date.getFullYear(), 
     month = +date.getMonth() + 1 < 10 ? '0' + parseInt(date.getMonth() + 1) : date.getMonth() + 1, 
     day = +date.getDate() < 10 ? '0' + date.getDate() : date.getDate(), 
     newDate = yr + '-' + month + '-' + day; 
    $("#dateupdated").val(newDate); 
    var url = "<?php echo base_url("resident/updateresident/{$resident->id }"); ?>" 
    $.ajax({ 
     url: url, 
     type: "POST", 
     data: new FormData(this), 
     contentType: false, 
     cache: false, 
     processData: false, 
     success: function (data) { 
      swal("Operation completed successfully."); 
      // var objs = $.parseJSON(data); 
      // var status=objs.status;   
     } 
    }); 
}); 
+0

あなたのコードを正しくフォーマットしてください –

答えて

0

swal({ 
    title: "Are you sure?", 
    text: "Are you sure that you want to cancel this order?", 
    type: "warning", 
    showCancelButton: true, 
    closeOnConfirm: false, 
    confirmButtonText: "Yes, cancel it!", 
    confirmButtonColor: "#ec6c62" 
}).then(function() { 
    // Your codes goes here 
}); 

ここで私は.then(function() {に変更,function(){を持っているので、それはあなたの関数内

をコードに動作しますし、また、私は変更ブラケットを持っているのSwaI関数の後にあなただけの}を完了持っていますが、})

を完了する必要が