2

私はあなたに -私のウェブサイトのSweetAlert . ここで、このコードを使用して SweetAlert を構成する必要があります。これにより、[OK] ボタンをクリックすると、POST formaction="/link/link" post="test=1" を介して送信されます。

swal({
    title: "Are you sure?",
    text: "You will not be able to recover this imaginary file!",
    type: " warning ",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes, delete it!",
    cancelButtonText: " No, cancel plx!",
    closeOnConfirm: false,
    closeOnCancel: false
}, function(isConfirm) {
    if (isConfirm) {
        swal("Deleted!", "Your imaginary file has been deleted.", "success");
    } else {
        swal("Cancelled", "Your imaginary file is safe: ) ", " error ");
    }
});

お聞きしたいのですが、どうやって組み込むことができますか。

4

4 に答える 4

1

post純粋な JS の場合 - これは値を含むパラメーターを投稿しますpost123

var formTest = document.createElement('form');
formTest.setAttribute("method", "post");
formTest.setAttribute("action", "");

var post = document.createElement("input");
post.setAttribute("type", "hidden");
post.setAttribute("name", "post");
post.setAttribute("value", "post123");
formTest.appendChild(post);

document.body.appendChild(formTest);
formTest.submit();

必要に応じて、jQuery を必要とする短くて素敵な AJAX 呼び出しを使用できます

于 2014-11-20T09:28:23.153 に答える
0

このコードを試してください。必要に応じて編集してください。

swal({
 title: "Are you sure?",
 text: "You will not be able to recover this imaginary file!",
 type: " warning ",
 showCancelButton: true,
 confirmButtonColor: "#DD6B55",
 confirmButtonText: "Yes, delete it!",
 cancelButtonText: " No, cancel plx!",
 closeOnConfirm: false,
 closeOnCancel: false },
  function() {
    $.ajax({
      type: "POST",
      data: {
        'data_id': id
      },
      url: 'http://localhost/project/method',
      success: function(data) {
        swal("Deleted!", "Your imaginary file has been deleted.", "success");
      },
      error: function(data) {
        swal("Cancelled", "Your imaginary file is safe: ) ", " error ");
      }
    });
  }
于 2016-03-30T08:10:28.000 に答える