Ich möchte in eine PHP-Datei umleiten, die mit Ajax aufgerufen wird. In der Datei schreibe ich die Umleitung. Der Umleitungscode funktioniert jedoch nicht. Ajax PHP Redirect auf eine URL
Dies ist der Code für die Ajax-Datei:
<?php
ob_start();
include 'admin/includes/front_controller.php';
if (isset($_POST['id'])) {
$job_id = intval($_POST['id']);
$job_id = 30;
$jobdetail = $db->getTableWhere("jobs", "jbid", $job_id);
$count = count($jobdetail);
if ($count <= 0) {
header("Location: jobs.php");
exit();
}
} else {
echo "There is an error processing your request";
}
?>
Dies ist der Ajax-Aufruf Ich benutze:
<script type="text/javascript">
$(".job-btn").on('click', function (e) {
e.preventDefault();
var id = $(this).data('id');
//alert(id);
var url = "<?php echo SITE_URL; ?>" + "jobdetail.php";
var info = 'id=' + id;
$.ajax({
type: "POST",
url: url,
data: info,
success: function (data) {
alert(data);
},
error: function (data) {
//alert(data.responseText);
//alert("Error occured in showing details");
}
})
});
</script>
Sie können nicht umleiten aus einer ajaxed Seite – madalinivascu
Ihre Ajax-Antwort sollte Anweisungen für Ihren Rückruf enthalten umleiten, dh die URL in der JSON – Scuzzy
Redirection sein sollte, kann nie in einem passieren AJAX. Sie müssen den Umleitungscode in 'success: function (data) {....' schreiben –