2017-07-31 6 views
1

JSを使用してフォームを送信しようとしていますが、HTMLを必要とせずに、ユーザー情報付きのテーブルがあり、JSを使用して自動的にボタンが追加されていますその情報をHTMLに渡すことはできません(JSテーブルはすべてのフォームを削除するHTMLテーブルを上書きします).JSのみを使用してPHPにクエリを送信する方法はありますか?JSから直接PHPフォームを送信する(HTMLなし)

この関数は(SwaIでの「を」部分では(私は)甘いアラート推測している)、警告が出力されている場合は、私はJSが

function banAccount(id, username){ 
    swal({ 
     title: "Do you really want to ban "+username+"?", 
     text: "Enter amount of days, -1 equals to permanent ban.", 
     input: 'number', 
     showCancelButton: true, 
     confirmButtonColor: "#DD6B55", 
     confirmButtonText: "Yes", 
     showLoaderOnConfirm: true, 
     preConfirm: function (duration) { 
      return new Promise(function (resolve, reject) { 
      setTimeout(function() { 
       if (duration === '0') { 
       reject('Please type -1 for permanent ban or a number greater than 1!') 
       } else { 
       resolve() 
       } 
      }, 2000) 
      }) 
     }, 
    allowOutsideClick: false 
    }).then(function(duration){ 
     action_id = id; 
     action_type = "ban"; 
     action_params = duration; 
     alert("id:"+action_id+", type:"+action_type+", params:"+action_params) 
     // Here's where I need to send "action_id", "action_type" and "action_params" to PHP 
    }); 
} 
+0

あなたは、Ajaxをタグ付けしていますが、それに精通していますか? Ajaxはあなたが必要とするものです – GrumpyCrouton

答えて

2

あなたはajaxを使用する必要があります。

$.ajax ({ 
    url: "PHP-PAGE-TO-POST-TO.php", 
    data: { action_id : action_id, 
      action_type : action_type, 
      action_params : action_params }, 
    success: function(result) { 
     alert("Hi, testing"); 
     alert(result); 
     //the variable "result" holds any value the PHP script outputs 
    } 
}); 
0

を作成]ボタンをクリックしたときに走っていますデータを正しいものにするには、データをPHPファイルに投稿してみませんか?

$.post("YOURFILE.php", { id: action_id, type: action_type, params: action_params }); 
関連する問題