【发布时间】:2019-03-22 18:59:31
【问题描述】:
我有一个关于 ajax 调用的问题,我不明白为什么我仍然得到这个空的成功调用。我尝试了过去的解决方案来解决这个问题,但我不知道这是什么原因。
您可以看到我的表格,然后当我单击更新、删除或添加操作时,甚至 print_r($_POST) 它仍然是空的。 然后当我去控制台时,我得到了这个错误。 选择的 attr 的值仍然发送到 php 文件
这是我的代码:
$(document).on('click', '.update', function(){
var user_ID = $(this).attr('id');
$.ajax({
url:"datatable/account/fetch_single.php",
method:"POST",
data:{user_ID:user_ID},
dataType:"json",
success:function(data)
{
console.log(data);
$('#account_modal').modal('show');
$('#username').prop("disabled", true);
$('#username').val(data.user_Name);
$('#email').val(data.user_Email);
$('#pass').val(data.user_Pass);
$('#con_pass').val(data.user_Pass);
$('#level').val(data.level_ID).change();
$('#status').val(data.user_status).change();
$('#action').val('Edit');
$('#operation').val('Edit');
$('.modal-title').text('Edit Account Info');
$('#user_ID').val(user_ID);
}
})
});
fetch_single.php
include('db.php');
include('function.php');
if(isset($_POST["user_ID"]))
{
$output = array();
$statement = $conn->prepare(
"SELECT * FROM `user_accounts`
WHERE user_ID = '".$_POST["user_ID"]."'
LIMIT 1"
);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
$output["level_ID"] = $row["level_ID"];
$output["user_Name"] = $row["user_Name"];
$output["user_Pass"] = decryptIt($row["user_Pass"]);
$output["user_Email"] = $row["user_Email"];
$output["user_status"] = $row["user_status"];
}
echo json_encode($output);
}
或者它可能是问题的原因是设计模板?
【问题讨论】:
-
您能否将此处的代码缩小到一个不起作用的特定操作/功能?当可能存在一个主要问题时,要经历很多事情。
-
@PatrickQ 好的先生。我已经编辑了我的问题
-
您是否使用浏览器的网络检查器查看原始请求和响应?
-
@PatrickQ 试过了,但我不确定我是否正确,是控制台和源附近的选项卡
标签: php ajax datatables