[英]Ajax redirect to URL after success
我有问题,我的函数成功后不会重定向。 我不为什么没有重定向...如果我将... href放在e.preventDefault()之后; 有时有效。
$('#nadwozie').change(function (e) {
if (window.confirm('Czy na pewno chcesz zmienić nadwozie/grafikę pojazdu ?')) {
var url = "raport_zapisanie_danepojazdu.php"; // the script where you handle the form input.
$.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(); // avoid to execute the actual submit of the form.
} else {
$("#nadwozie").val(previous);
previous = $(this).val();
}
});
您可以更换:
window.location.href = "raport.php?id=" + <?php echo $raport[0]['id'];?> +"&nadwozie=" + $(this).val();
与:
window.location.assign("raport.php?id=" + <?php echo $raport[0]['id'];?> +"&nadwozie=" + $(this).val());
参见https://developer.mozilla.org/en-US/docs/Web/API/Location/assign
实际上,Assign()重定向到给定的URL,而href仅返回该URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.