I have 1 javascript
variable and i want to pass i to my php
file. i search about it and i find that to use ajax
but i don't really know how use it ! here is my code .
where am i do 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.php
file :
<?php
if(isset($_POST['newMessages']))
{
$uid = $_POST['newMessages'];
echo $uid;
}
?>