Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Back to previous page in AJAX Call

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.com/qs/56239790

like image 722
Daniel Avatar asked May 25 '19 12:05

Daniel


1 Answers

I'm not certain I understand you completely. 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.

like image 54
Michael Paccione Avatar answered Nov 04 '22 06:11

Michael Paccione