php - 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 as sold</a>
有人可以解释为什么会遇到这个问题,因为控制台日志显示success
但在 php 中没有收到数据
解决方案
推荐阅读
- python - sphinx 有类似于 doxygen 的 \page 的东西吗?
- javascript - 使用来源不安全的 crypto.subtle
- sql - 每天在 SCD-2 中更新约 3000 万条记录
- laravel - Laravel 对多个角色的同一资源的权限(Spatie)
- android - React Native flatlist 在 android 中不可滚动
- snowflake-cloud-data-platform - 在雪花中连续排序值
- geocoding - Gremlin 查询以获取 100 英里半径内的位置
- javascript - 使用 react-google-maps 自定义弹出窗口
- reactjs - 卷曲表达式中的 JSX 卷曲表达式
- flutter - Flutter查找PDF的宽度和高度