[英]Redirect AJAX response URL from PHP header
I have an AJAX POST that is sending back a successful response from my PHP file newPNRsubmit.php
:我有一个 AJAX POST,它从我的 PHP 文件newPNRsubmit.php
发回一个成功的响应:
if(isset($_POST['ticketentry'])){
$_SESSION['ticketEntry'] = 1;
header("location: pnr-details?id=".$pnrid);
}
However I would like to use the AJAX response that I am receiving into window.location
但是我想使用接收到window.location
的 AJAX 响应
This is the response:这是回应:
XHR finished loading: GET "https://example.com/pnr-details?id=240".
This is my AJAX structure:这是我的 AJAX 结构:
$.ajax({
type: "POST",
url: "newPNRsubmit.php",
data: {
bookingdate: bookingdate,
airline_id: airline_id
},
cache: false,
success: function(data, url) {
$('#NewPNRModal').modal( 'hide' );
},
error: function(xhr, status, error) {
console.error(xhr);
}
});
return false;
How can I correctly parse the URL that I am receiving into window.location
?如何正确解析我收到的 URL 到window.location
?
UPDATE: This is the response from console tab.更新:这是来自控制台选项卡的响应。 The second GET XHR
is showing the link I need for window.location
.第二个GET XHR
显示了我需要的window.location
链接。 Should I update the header location to send JSON
data in my PHP
file in order for this to work?我应该更新标头位置以在我的PHP
文件中发送JSON
数据以使其正常工作吗?
Either return a URL in the body instead of a header, or get the header like so:要么在正文中返回一个 URL 而不是标题,要么像这样获取标题:
success: function(data, URL, jqXHR) {
window.location.href = jqXHR.getResponseHeader("location");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.