Good evening. Help to correctly send a variable from JavaScript to a PHP file.

function spin(id){ $('#ro').removeAttr('class'); setTimeout(function(){$('.spinpage').fadeOut('fast')},0); $.post('/ro.php', { id : id }, function(data){ var rol = data 

How to correctly transfer the rol variable to the qer.php file as a post request asynchronous. I tried to do it myself, but my script refused at all.

    2 answers 2

    Here is an example of a click, for example. In the data substitute your data.

     $('#send').on('click', function () { $.ajax({ url: 'post.php', method: 'POST', data: {'username': 'Jack', 'password': 'secret'}, success: function (s) { console.log(s); }, error: function (e) { console.log(e); } }) }) 
    • Here's how to pass the rol variable under the name test for example - TheAs110z
    • @ TheAs110z data: {'test': rol}, - Vyacheslav Danshin
     // Первый запрос $.post('/ro.php', { id : id }, function(data){ // Когда первый запрос вернул данные var rol = data; // Отправить их по второму адресу $.post('/ger.php', { test : rol }); });