dtdfj08626 2013-08-12 18:16 采纳率: 0%
浏览 53
已采纳

PHP / Ajax代码无法正常工作

I can't figure out why this isn't working! The idea is the code is supposed to run a php script on another page that will check for changes in the DB state. Then it will return a string that will update the CURRENT page.

(External) PHP:

$QgetShift = mysql_query("SELECT * FROM shifts");

$num = mysql_num_rows($QgetShift);

if(isset($_POST['ajax'])) {
    if(isset($_SESSION['data'])) {

        $data = $_SESSION['data'];      
        if($data != $num){
            $_SESSION['data'] = $num;
            echo "WORKING";
        } else {
            echo "NOT WORKING";
        }
    } else {
        $_SESSION['data'] = $num;
        echo "started";
    }
}

HTML:

<button type="button" id="clickMe">Click Here</button> <br />
                <div id="data"></div>

Javascript:

$('#clickMe').click(function(){
  $.ajax({
    method: 'post',
    url: 'function.php',
    data: {
      'ajax': true
    },
    success: function(data) {
      $('#data').text(data);
    }
  });
});

Can anyone tell me if there is an error somewhere?

  • 写回答

2条回答 默认 最新

  • dongyao4419 2013-08-12 19:02
    关注

    Wow I'm dumb, the link was wrong :/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 oracle数据库备份表如何操作
  • ¥15 软件定义网络mininet和onos控制器问题
  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新