<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
:
此外,没有必要将 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/