redirect to href when ajax error
redirect to href when ajax error
Hi all
Is there a way to set default return url when ajax error ?
When user disconnect I close current session.
If user go to previous page (history back) the page is displayed and a datatable message explain data was not set correctly.
So is there a way to set no message and url to redirect (in my case login page) ?
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I don't quite follow, but you can set the URL with
ajax.url()
. You could also test the ajax before initialising the table, or possibly ensuring valid JSON is sent.Colin
Hi @colin
Thanks for answer
In fact url is set correctly to get data.
When user click on disconnect I unset cookie session.
At each page start, I ensure session is ok using php code, and if not I redirect to login page using header(...), but going to previous page do not execute php, just display computed html page
So when a history back is clicked on browser, the previous page is displayed, ajax is called and data can not be found, because no cookie is set to ensure who is online.
The message about invalid json is displayed.
If I click on refresh page, php is launched again and I am redirected to the login screen.
You tell me I can ensure valid JSON is send.... I try an do at ajax url page start verify if session condition are OK. If not I just return json_encode(""), so no message is displayed, but page stay displayed explaining waiting for data.
So if an error return url should be set on malformed json response, the redirect page should be displayed with no message.
Hope my explanation are clear...
There are two options here:
xhr
to see that parameter and subsequently callwindow.location.reload()
.I'd say option 1 would be easiest.
Allan
Hi @allan
Thanks.
I'll have a look in this direction.
Bob