小编Ant*_*ina的帖子

Wordpress admin ajax.php 400 错误请求

事实证明,我正在制作一个 Wordpress 插件,其中我需要对 Wordpress 的文件“admin_ajax.php”进行 AJAX,但是在发送请求时,客户端给了我错误 400(错误请求)而我没有明白是什么原因。

捕获

https://i.stack.imgur.com/5SiDd.png

https://i.stack.imgur.com/tPD6o.png

Javascript:

$.post(window.dibibot.ajax_uri, {
    action: "dibibot_check_message_read",
    to: (window.dibibot.USER_KEYS.split(":")[1]).toString(),
    message_id: JSON.stringify(data.message)
}, function(response) {
    console.log(response);
});
Run Code Online (Sandbox Code Playgroud)

Ajax php 函数:

<?php
    function dibibot_check_message_read() {
        global $wpdb;
        $conversation_guid = $_POST['to'];
        $message_id = json_decode($_POST['message_id'], true);

        $conversation = $wpdb->get_var("SELECT metadata FROM " . $wpdb->prefix . "dibibot_conversations WHERE guid = '".$conversation_guid."'");
        $conversation = maybe_unserialize($conversation);
        for ($j=0; $j < count($message_id) ; $j++) { 
            for ($i=0; $i < count($conversation); $i++) {
                if($conversation[$i]['id'] == $message_id[$j]) {
                    $conversation[$i]['status'] = 2;
                    break; …
Run Code Online (Sandbox Code Playgroud)

javascript php ajax wordpress plugins

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

ajax ×1

javascript ×1

php ×1

plugins ×1

wordpress ×1