Storing Jquery Variable into Php database

jQuery(document).ready(function ($) {

  $("#coin").click(function () {
    var flipResult = Math.random();
    $("#coin").removeClass();
    setTimeout(function () {
        var coinResult = " Heads"
      if (flipResult <= 0.5) {
        $("#coin").addClass("heads");
        console.log(coinResult);
      } else {
    var coinResult = "Tails"
        $("#coin").addClass("tails");
        console.log(coinResult);

      }
      $('#table_of_results').append('<tr><td>' + coinResult + '</td></tr>');

 for(i=0;i<1;i++){

    $.ajax({ type:"post", url:"server.php?p=add", data: coinResult, datatype: "text", success: function(postresult){ console.log("success");}  })

}

Got the coin to flip and append table element correctly but it wont post to server any idea why?

You’ll probably have to post the contents of server .php…since that is the area you mention is NOT working.

You posted the code/routine that you said IS working…so its of no use really.

In your server.php file… ensure you are at least getting the variable/data…

at that point you’ll know if its a data passing issue, or a database writing/connection issue.

Sponsor our Newsletter | Privacy Policy | Terms of Service