I have a checkbox that sends an AJAX request everytime the state of the checkbox is changed (checked/unchecked). I was testing everything in Chrome, and it all works fine.
However, it is when I use Firefox or IE, the AJAX request does not change the value in the SQL server. I'm a little confused of why it's not working, and I'm fairly new to JS and JQuery, so any help would be greatly appreciated.
Here is the function where I use AJAX to call a PHP page to change the checkbox value.
//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();
}
}
Here is the line in PHP where it shows the checkbox status:
<?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;
}
?>
If you guys need more information, just let me know. Thank you!
Aucun commentaire:
Enregistrer un commentaire