在ajax中传递数据时获得500内部错误。单击功能可以正常工作,如果我更改ajax页面可以正常工作,但是当前页面无法工作。
<script>
function saveBooking()
{
var usernamesend = document.getElementById("username").value;
if(usernamesend=="")
{
alert("Please fill Name");
return false;
}
var emailsend = document.getElementById("email").value;
if(emailsend=="")
{
alert("Please fill Email");
return false;
}
var phonesend = document.getElementById("phone").value;
if(phonesend=="")
{
alert("Please fill Phone Number");
return false;
}
var dateokk = '<?php echo $newDate123; ?>';
var paymentMethod = "spot";
var slotPrice = document.getElementById("slotPrice").value;
var slotTime = document.getElementById("slotTime").value;
var totalPrice = '<?php echo $originalSlotFee; ?>';
$.ajax({
type: "POST",
url: "savebookingajax.php",
data: {usernamesend:usernamesend,emailsend:emailsend,phonesend:phonesend,dateokk:dateokk,paymentMethod:paymentMethod,slotPrice:slotPrice,slotTime:slotTime,totalPrice:totalPrice},
success : function(res){
alert(res);
return false;
}
});
}
</script>
答案 0 :(得分:0)
您在data
中输入的键不正确
data: {usernamesend:usernamesend,emailsend:emailsend,phonesend:phonesend,dateokk:dateokk,paymentMethod:paymentMethod,slotPrice:slotPrice,slotTime:slotTime,totalPrice:totalPrice},
键usernamesend, emailsend, phonesend, dateokk, paymentMethod, slotPrice, totalPrice
将替换为html页面元素的实际值,而在php端,您将这些键用作键。
使用键作为字符串值:
data: {"usernamesend":usernamesend,"emailsend":emailsend,"phonesend":phonesend,"dateokk":dateokk,"paymentMethod":paymentMethod,"slotPrice":slotPrice,"slotTime":slotTime,"totalPrice":totalPrice},