I have 1 javascriptvariable, and I want to transfer me to my file php. I'm looking for this, and I find what to use ajax, but I really don't know how to use it! here is my code. where am i doing wrong? my.js file:
var message1 = message.message;
var jq = document.createElement('script');
jq.src = "https://code.jquery.com/jquery-1.10.2.js";
document.querySelector('head').appendChild(jq);
$(document).ready(function() {
$.ajax({
type: "POST",
url: 'http://localhost/a.php',
data: { newMessages : message1 },
success: function(data)
{
alert("success!");
}
});
});
my a.phpfile:
<?php
if(isset($_POST['newMessages']))
{
$uid = $_POST['newMessages'];
echo $uid;
}
?>
source
share