I'm having an issue that I have been trying to research and fix for hours now and I am at my wits-end in not understanding why it's not working correctly.
I have a jQuery dialog (via jQuery UI) pop-up when someone wants to delete an item (by clicking on a delete icon image and calling a JS function with a supplied "id" integer). The pop-up dialog is working properly and comes up with all the available information and button options. Here's the code for that:
function removeItem(id) {
var rid = id;
$("#dialog").dialog({
title: "Removal Confirmation",
resizable: false,
height: 200,
modal: true,
show: {
effect: "blind",
duration: 800
},
buttons: {
"Confirm": function() {
$.post("includes/inc_details.php", {
"type":"remove",
"id":rid
});
window.location.reload();
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
}
});
}
When the "Confirm" button within the dialog is clicked, it's suppose to .post to a php file for further processing (code for that portion is below), and when complete will reload the browser window and then close the dialog.
However, what is routinely happening is the page just looks like it's reloading and then the dialog closes but the item doesn't get deleted. I've watch the processing via chromeDev tools and it appears that when the .post php file is called the two parameters are not sent with it. (I've used similar .posts other places - albeit without a jQuery UI dialog box - with no issues).
HELP!
PHP code being called via the .post method:
$sql = "select * from shopping_cart WHERE id=$_POST[id] LIMIT 1";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if ($row["Type"] == "CouponUsed") {
$sql_delete_free_item = "delete from shopping_cart where ProductID=".$_SESSION["freeProductId"]." and SessionID='".session_id()."'";
$query = mysql_query($sql_delete_free_item);
unset($_SESSION["freeProductId"]);
}
$sql_id = "SELECT ProductID FROM shopping_cart WHERE id=$_POST[id] LIMIT 1";
$result_id = mysql_query($sql_id);
$row_id = mysql_fetch_assoc($result_id);
$sql_remove = "DELETE FROM shopping_cart WHERE id=$_POST[id] LIMIT 1";
if (mysql_query($sql_remove)) {
$sql_remove2 = "DELETE FROM shopping_cart_single WHERE singleid=$_POST[id]";
mysql_query($sql_remove2);
}
mysql_close($conn);
exit();
Thank you, in advance!