When you press a button and confirm, an Ajax request is performed.

function Validator(id_){ if(confirm("Вы подтверждаете операцию?") ){ var ttt= document.getElementById(id_); alert(ttt.id); $.ajax({ type: 'GET', url: '2.php', data:{'1btn':'1'}, success: function(data) { $("p").html(data); } }); return(true); }else{ alert("Операция отменена!"); return(false); } } <p></p> <button id="1btn" class="b1" value="open" onclick="JavaScript:return Validator(this.id);">Start</button> <button id="50btn" class="b1" value="open" onclick="JavaScript:return Validator(this.id);">Stop</button> <button id="51btn" class="b2" value="open" onclick="JavaScript:return Validator(this.id);">Test</button> 

How in data: {'1btn':'1'} to transfer the value of the variable ttt.id?

  • data:{1btn:'1', id: ttt}, then in php file you get the value of the variable via $_GET("id") - Dmitriy Kondratiuk
  • As far as I remember, you can only transfer in the request itself, for example 2.php? id = + ttt.id, and then read success (I don’t remember exactly which object contains the variable with the request text) - akrasnov87

2 answers 2

Why create extra variables if you already have an input parameter in the function and have id? just replace

data:{1btn:'1'}

on

data:{'id':id_}

and when sending to the browser console (in the "Network" section), check what data it sends.

    Did so. works.

     function Validator(id_){ if(confirm("Вы подтверждаете операцию?") ){ var ttt= document.getElementById(id_); //alert(ttt.id); $.ajax({ type: 'GET', url: 'runner.php?' + ttt.id + '=1', success: function(data) { $("p").html(data); } }); //return(true); }else{ alert("Операция отменена!"); //return(false); } }