首页 > 解决方案 > AJAX 日志显示成功,但没有数据发布到 php

问题描述

我使用 ajax 来发布 htmldata-attr值,但是当我发布时,我得到以下登录控制台

在控制台日志中,我得到了这个结果

   success
   posted_ads:201 array(0) {
                     }

由于日志状态AJAX成功,所以我认为 php 中可能存在错误,因此使用var_dump()方法来查找是否有任何数据通过表单请求但没有转储数据。

为什么我没有得到任何数据的任何解决方案php

PHP

<?php 
header('Content-type: application/json');
include("$_SERVER[DOCUMENT_ROOT]/include/config.php"); 
var_dump($_POST);
?>

这是我的代码

       $(document).ready(function () {
            $('#myModal').on('show.bs.modal', function (e) {
                e.preventDefault();
                const action = $(this).attr('data-act');


                var hash = $(e.relatedTarget).data('hash');
                var para = $(e.relatedTarget).data('para');
                var ref = $(e.relatedTarget).data('ref');
                $.ajax({
                    //data :{action: "showroom"},
                    url: '/include/ajax/dashboard_get_single_card.php', //php page URL where we post this data to view from database
                    type: 'POST',
                    data: {"action": action, "hash": hash, "para": para}, //Pass $id
                    dataType:'text',
                    success: function (data, status) {
                        //window.location.href = data;
                        console.log(status);
                        console.log(data);
                        $("#fetched").html(data);
                    },
                    error: function (xhr, textStatus, error) {
                        $("#fetched").html(xhr.responseText);
                        console.log(xhr.responseText);
                        console.log(xhr.statusText);
                        console.log(textStatus);
                        console.log(error);
                        //window.location.href = '/404.php';
                    }
                });


            });
            return false;
        });

HTML

<a href="#myModal" class="btn btn-primary btn-block btn-sm" id="custId" data-toggle="modal" data-act="msold" data-hash="6d8ce77d206011027297b693be999704" data-para="A4IxzuRP8ATv"><i class="mi mi-sml">local_offer</i>Mark&nbsp;as&nbsp;sold</a>

有人可以解释为什么会遇到这个问题,因为控制台日志显示success但在 php 中没有收到数据

标签: phpajax

解决方案


推荐阅读