错误 500 使用 AJAX 开机自检更新内部服务器表



我是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. 我的外部文件代码未读.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!";
    }

提前感谢您的时间!

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

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

你可以在这里找到一些有用的东西(至少对我来说)WordPress Ajax不更新数据库。

干杯。

最新更新