Acutally I have a working AJAX Call that get me back after succeed to a static defined Site.
$.ajax({
url: 'myPage.php',
type: 'get',
data: {TestaufstellungID:TestaufstellungID, Datum: Datum},
dataType: 'text',
success:function(data){
window.location = "staticPage.php";
console.log('SQL Eintrag Erfolgreich Aktuallisiert');
},
error: function(jqxhr, status, exception) {
console.log(exception);
}
});
It works fine with window.location
but I want a dynamic site, back to this site where the use came from, like in PHP:
header('Location: ' . $_SERVER['HTTP_REFERER']);
Please don't give me answer like history.go(-1);
becasue I don't want cached sites. Should be do the same like the PHP code, because in some cases I need the page URL with all string (Get-Method
).
My reference Post, to understand the step by step page working order, I want to be back all in all to the first step (page) but this page is not always the same one.
Acutally I have a working AJAX Call that get me back after succeed to a static defined Site.
$.ajax({
url: 'myPage.php',
type: 'get',
data: {TestaufstellungID:TestaufstellungID, Datum: Datum},
dataType: 'text',
success:function(data){
window.location = "staticPage.php";
console.log('SQL Eintrag Erfolgreich Aktuallisiert');
},
error: function(jqxhr, status, exception) {
console.log(exception);
}
});
It works fine with window.location
but I want a dynamic site, back to this site where the use came from, like in PHP:
header('Location: ' . $_SERVER['HTTP_REFERER']);
Please don't give me answer like history.go(-1);
becasue I don't want cached sites. Should be do the same like the PHP code, because in some cases I need the page URL with all string (Get-Method
).
My reference Post, to understand the step by step page working order, I want to be back all in all to the first step (page) but this page is not always the same one.
https://stackoverflow./qs/56239790
Share Improve this question edited Jun 9, 2019 at 12:20 double-beep 5,53719 gold badges40 silver badges49 bronze badges asked May 25, 2019 at 12:15 DanielDaniel 6684 silver badges17 bronze badges 3- Why are you using AJAX at all? – Jared Smith Commented May 25, 2019 at 12:18
- Thats just one example Ajax Call. I need calls to the server without reloading. And i edit the post with my reference question to understand the Background. – Daniel Commented May 25, 2019 at 12:44
- Are you building a single page application? If yes, you should look into using a client-side router: github./krasimir/navigo. If not, why are you loading the previous page's html with an ajax call? – Neil VanLandingham Commented Jun 2, 2019 at 12:55
2 Answers
Reset to default 5 +50I'm not certain I understand you pletely. However...
$previous = "javascript:history.go(-1)";
if(isset($_SERVER['HTTP_REFERER'])) {
$previous = $_SERVER['HTTP_REFERER'];
}
For redirecting with PHP
header("Location: $previous");
For testing with a HTML link
<a href="<?= $previous ?>">Back</a>
I hope this is helpful.
To Redirect to the Previous worked page.
window.history.back();
or
history.back();
It redirects to the previous page that we used to work. but when you want to redirect to the particular URL you can use that link in the href tag.
click Here for Reference the link tags