I am trying to update one field through ajax which is not working. below is the code
Jquery:
<script type="text/javascript">
function changeStatus(changeStatus,userId) {
var data="changeStatus="+changeStatus+"&userId="+userId;
$.ajax({
type:'GET',
url:'myfunctions.php',
data:data,
success:function() {
alert('Updated');
}
});
}
</script>
php:
<?php
function changeStatus($changeStatus,$userId){
$userId=$_GET['userId'];
$userStatus=$_GET['userStatus'];
switch($userStatus) {
case "1":
$changeStatus=0;
break;
case "0":
$changeStatus=1;
break;
default:
$changeStatus="";
}
$Query="UPDATE blog_users SET blog_user_status='$changeStatus' WHERE blog_user_id='$userId'";
$Result=mysql_query($Query);
}
if(isset($_GET['userId']) && isset($_GET['userStatus'])) {
changeStatus($changeStatus,$userId);
}
?>
and here is how i call the function:
<a href="#" onclick="changeStatus($changeStatus,$userId)"><?php echo $action; ?></a>
Just to let know that i tried this only in php by passing get values through href. and it was working...