dongzhanyan3667 2013-06-23 03:09
浏览 32

Ajax PHP更新无法正常工作

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...

  • 写回答

2条回答 默认 最新

  • duananyantan04633 2013-06-23 03:29
    关注
    <a href="#" onclick="changeStatus(<?php echo $changeStatus; ?>,<?php echo $userId; ?>)"><?php echo $action; ?></a>
    

    Try with that

    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图