I have a form that saves some data in a MySQL table, and after doing it, the website is redirecting to the index.php page, which I don't want to occur, I just want it to stay in the same page.
I have some ajax passing the form values:
$("#incomeSave").click(function() {
alert("incomeSave");
$.ajax({
type:"POST",
url: "actions.php?action=incomeSave",
data: "date=" + $("#incomeDate").val() + "&value=" + $("#incomeValue").val() + "&category=" + $("#incomeCategory").val() + "&subcategory=" + $("#incomeSubCategory").val() + "&account=" + $("#incomeAccount").val() + "&description=" + $("#incomeDescription").val(),
success: function(result) {
alert(result);
}
})
})
Then the query is executed:
if ($_GET['action'] == "incomeSave") {
if (!$_POST['value']) {
echo "Valor vazio";
} else {
mysqli_query($link, "INSERT INTO incomes (`user_id`,`income_date`,`income_value`,`income_category`,`income_subcategory`,`income_account`,`income_description`) VALUES ('1','". mysqli_real_escape_string($link, $_POST['date'])."','". mysqli_real_escape_string($link, $_POST['value'])."','". mysqli_real_escape_string($link, $_POST['category'])."','". mysqli_real_escape_string($link, $_POST['subcategory'])."','". mysqli_real_escape_string($link, $_POST['account'])."','". mysqli_real_escape_string($link, $_POST['description'])."')");
echo "After SQL";
}
}
What should I do so the page is not redirected to the index.php?