0

From the below code I need to pass the value of "data1" to php file using variable.

Js file:

document.getElementById('data1').innerHTML=e.point.name;

Html Code :

  <p id="data1"></p>

From the above js and html file how can I pass the value of "data1" to php..

sharmila
  • 175
  • 2
  • 19

2 Answers2

0

Try this

$(document).ready(function(){

var data1 = $('#data1').text();

$.ajax({
  url: "script.php",
  type: "POST",
  data: {myvar : data1},
  success: function (data) {
     console.log(e)
  },
  error: function (e) {
     console.log(e)
    }
   });
});

Than in your php script access the variable like this

$my_variable = $_POST['myvar'];
Suraj Rana
  • 70
  • 13
0

You can not send JavaScript variable value to PHP, you can send PHP to JavaScript, If you want to send data you have to use url and pass. make it url and send.

USE this [Dublicate]

How to get JavaScript variable value in PHP