I don't know what is wrong here I tried this link to know how can I interact between php and jquery
here is my code but it will alert an empty box,I'm sure that it can't read the test.php but I don't know why?!
mytest.php
<?php
if($_GET['cookie']!='')
{
setcookie("cookie", $_GET['cookie']);
echo 'set cookie: ' . $_GET['cookie'];
}
else
echo 'get cookie: ' . $_COOKIE["cookie"];
?>
test.html:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Ajax Set & Get Cookie</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready( function() {
$("#setcookie").click(function() {
if($("#cookievalue").val() != '')
setCookie( $("#cookievalue").val() );
});
$("#getcookie").click(function() {
getCookie();
});
});
function setCookie(value)
{
$.get("mytest.php", { cookie: value},
function(data){
alert(data);
}
);
}
function getCookie(value)
{
$.get("mytest.php", { },
function(data){
alert(data);
}
);
}
</script>
</head>
<body>
<div align="center">
Cookie: <input type="text" id="cookievalue" value="" />
<br />
<input type="button" id="setcookie" value="Set Cookie" />
<input type="button" id="getcookie" value="Get Cookie" />
</div>
</body>
</html>