gpt4 book ai didi

javascript - Ajax提交返回错误但更新数据库正常

转载 作者:行者123 更新时间:2023-11-28 04:26:04 26 4
gpt4 key购买 nike

<script>
function addprescription() {
var Case_Histroy=$('#Case_Histroy').val();
var Medication=$('#Medication').val();
var Note=$('#Note').val();
var pname="<?php echo($patient->getUsername()); ?>";
var dname="<?php echo($doctor->getUsername()); ?>";
var id="<?php echo($id); ?>";
frmData={Case_Histroy:Case_Histroy,Medication:Medication,Note:Note,pname:pname,dname:dname,id:id}
console.log( frmData);
$.ajax({
type: "POST",
url: "loadfiles/AddAppointmentSubmit.php",
data: frmData,
success: function (msg) {
alert(msg);
$("#alert").html(msg)
}
,
error : function () {
alert("failure");
}
});
}
</script>

我有一个提交表单的功能。但ajax功能警告其失败。但数据库似乎已更新。当我点击按钮时。我在控制台中找不到原因。

这是php文件

<?php
echo "I'm in";
include "../../Adaptor/mysql_crud.php";
include ("Prescription.php");
$prescription=new Prescription();
if(isset($_POST)){
$Note=htmlspecialchars($_POST['Note']);
$Case_Histroy=htmlspecialchars($_POST['Case_Histroy']);
$medication = htmlspecialchars($_POST['Medication']);
$pname=$_POST['pname'];
$danme=$_POST['dname'];
$id=$_POST['id'];
$prescription->insert($pname,$danme,$Case_Histroy,$medication,$Note,$id);
?>
<div class="alert alert-success" id="alert"><strong><?php echo "Submitted succesfully"; ?></strong></div>
<?php
}
?>

最佳答案

尝试添加 else给您的声明if :

插入($pname,$danme,$Case_Histroy,$medication,$Note,$id); ?> <强> <强> }?>

此外,没有必要将 php 粘贴在 <div> 的中间。你可以只使用 echo在开始时,因为您没有向其中引入任何变量:

echo '<div class="alert alert-success" id="alert"><strong>Submitted successfully</strong></div>';

关于javascript - Ajax提交返回错误但更新数据库正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45049180/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com