我有一个复选框,每次复选框的状态(选中/取消选中)时都会发送一个AJAX请求。我正在测试Chrome中的所有内容,一切正常。
但是,当我使用Firefox或IE时,AJAX请求不会更改SQL Server中的值。我有点困惑为什么它不起作用,而且我对JS和JQuery相当新,所以任何帮助都会非常感激。
这是我使用AJAX调用PHP页面来更改复选框值的函数。
//This function handles the clicking of checkboxes in the list
//It sends an ajax POST message to a separate php file that handles the database updating
function checkboxClicked(checkboxType, ticketNumber){
$.ajax({
type: "POST",
url: 'updateCheckbox.php',
dataType: 'json',
async: 'true',
data: {checkboxType: checkboxType, ticketNumber: ticketNumber},
success: function(result, status){
if (status == "success"){
console.log("Status: " + status + ", Result: " + result);
}
}
});
if(checkboxType == "Received"){
window.location.reload();
}
}
以下是PHP中显示复选框状态的行:
<?php
//This loop populates the ticket display using the records in the database
while($recordSet->EOF == false){
$ticketNumber = $recordSet->Fields['TicketNumber'];
$dateSubmitted = $recordSet->Fields['DateSubmitted'];
$department = $recordSet->Fields['Department'];
$courseNo = $recordSet->Fields['CourseNumber'];
$instructorName = $recordSet->Fields['InstructorName'];
$received = ($recordSet->Fields['Received']) ? "checked" : "unchecked";
$sendReminder = ($recordSet->Fields['SendReminder']) ? "checked" : "unchecked";
$email = $recordSet->Fields['Email'];
$CC = $recordSet->Fields['CC'];
$strHTML = "<tr><td>$dateSubmitted</td>\n";
$strHTML .= "<td>$department</td>\n";
$strHTML .= "<td>$courseNo</td>\n";
$strHTML .= "<td style='word-break: break-all'>$instructorName</td>\n";
$strHTML .= "<td align='center'> <input type='checkbox' id='received' ".$received." class='receivedCheckbox' onclick='checkboxClicked(\"Received\", ".$ticketNumber.")'/></td>\n";
$strHTML .= "<td align='center'> <input type='checkbox' id='sendReminder' ".$sendReminder." class='sendReminderCheckbox' onchange='checkboxClicked(\"SendReminder\", ".$ticketNumber.")' data-email='".$email."'/></td>\n";
$strHTML .= "<td style='word-break: break-all;' align='center'> <a id='checkReceived' href='#' onClick='checkReceived(\"$received\", \"$email\")'>".$email."</a></td>";
$strHTML .= "<td align='center'> <button onclick=\"window.open('urlhere', '_self')\">Edit</button>\n";
$strHTML .= "<td align='center'> <button onclick=\"window.open('urlhere')\">Print</button> </td>\n";
$strHTML .= "</tr>\n";
echo $strHTML;
$recordSet->MoveNext;
}
?>
如果您需要更多信息,请告诉我们。 谢谢!
答案 0 :(得分:0)
可能你应该尝试:
$received = ($recordSet->Fields['Received']) ? "checked='checked' " : "checked='' ";
$sendReminder = ($recordSet->Fields['SendReminder']) ? "checked='checked' " : "checked='' ";