I'm facing an issue with my function as it doesn't redirect after a successful operation. I'm not sure why the redirection is not happening consistently. Sometimes, adding ...href after e.preventDefault(); seems to work.
$('#nadwozie').change(function (e) {
if (window.confirm('Are you sure you want to change the vehicle body/graphics?')) {
var url = "raport_zapisanie_danepojazdu.php"; // the script where form input is handled.
$.ajax({
type: "POST",
url: url,
data: $("#FormRaport").serialize(), // serializes the form's elements.
dataType: "text",
success: function (data) {
window.location.href = "raport.php?id=" + <?php echo $raport[0]['id'];?> +"&nadwozie=" + $(this).val();
},
error: function (request, status, error) {
//alert(request.responseText + status + error);
}
})
;
e.preventDefault(); // prevent the actual submit of the form.
} else {
$("#nadwozie").val(previous);
previous = $(this).val();
}
});