简体   繁体   中英

How can I get a variable from JS into MySql database?

I want to save the variable from JS named count into my MySql database.

let count = 0;
countup.addEventListener("click", function() {
    count = count + 1;
    counter.innerText = count;
    let avgberechnung = count / 365;
    avg.innerText = avgberechnung + " Ø Köpfe am Tag";                       
},false);

How can I do this?

Possible solution with php server

  1. Use ajax to send request

    $.post('save.php',{count:count})

    .done(function(data){

    alert("success -".data);

    });

  2. Create a PHP file (here save.php) to save the post data.

helpful links

Insert data into mysql database

Jquery ajax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM