How to send variable value from php to js
I want to send variable from php to js . I want to work this file like
that js sends value php file then php works on this code and return again
variable like true or false after that js controls and shows something
users.I am Sorry for my poor English :D
<?php
if(!empty($_POST['a'])){
$value=1;
echo '{"a":"'.$value.'"}';
}else{
?>
<script src="assets/plugins/jquery-1.10.1.min.js"
type="text/javascript"></script>
<script src="assets/plugins/jquery-migrate-1.2.1.min.js"
type="text/javascript"></script>
<script>
function sendValue($page,$value){
$.post($page, $value ,
function(data){
if(data.a==1){
alert("its work");
}else{
alert("oh no Houston we have a problem !!");
}
}
)};
</script>
<a href="#" onclick='sendValue("a.php",{a:"1"});'
>blabla</a>
<?php
}
?>
No comments:
Post a Comment