【问题标题】:Error 500 Internal server updating table with AJAX POST错误 500 内部服务器使用 AJAX POST 更新表
【发布时间】:2016-05-14 18:17:06
【问题描述】:

我是 AJAX 的新手,所以我可能遗漏了一些东西。我在通过外部 php 源更新 mysql 表时发现了一个问题(错误 500 内部服务器)。

基本上我正在尝试执行以下操作:

点击按钮>调用ajax函数>调用php>更新mysql表。

我正在使用 wordpress 和 MAMP。

这是我的代码。

1.按钮

<button onclick="unreadMessage()" class="messages btn btn-menu dropdown-toggle" data-toggle="dropdown" type="button">

2。 jQuery / AJAX 函数

function unreadMessage(){
        $.ajax({
            type: "POST",
            url: "<?php bloginfo('template_url'); ?>/lib/unread.php",
            data: { 'read': '1' },
            success:function() {
                alert("ok");
            }
        });
    }

3.我的外部文件代码 unread.php

    global $current_user, $wpdb, $wp_query;
    get_currentuserinfo();
    $uid = $current_user->ID;
    $read = $_POST['read']; 
    $sql = "update ".$wpdb->prefix."project_pm set rd='$read' where id='{$row->id}' AND user='$uid' and notify='1'";
       if(mysqli_query($sql)){
       }
       else {
        return "failed!";
    }

提前感谢您的宝贵时间!

【问题讨论】:

  • if(mysqli_query($sql)){ 你没有在这里连接。并检查您的日志。 return "failed!"; 对你没有帮助。找出真正的错误。
  • ...我闻到了答案(正在研究中)
  • 链接标识符在哪里?查询中?
  • mysqli 查询语法:mysqli_query(connection,query,resultmode);
  • 看看wpdb class

标签: php jquery ajax wordpress


【解决方案1】:

对于下一个路过的用户来说很好。通过按钮触发的ajax调用实际更新wordpress数据库是正确的方法。

  1. 在functions.php中插入动作
  2. 将动作调用到 jQuery / Ajax 函数中
  3. 链接到按钮。

你可以在这里wordpress ajax not updating database找到一些有用的东西(至少对我来说)。

干杯。

【讨论】:

    猜你喜欢
    • 2014-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    • 2019-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多