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条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程