how redirect in AJAX requests
- mlha
- Member | 58
NonAJAX solution:
- Nette will create form component and send it to user.
- User will complete and submit form.
- Nette will recreate form component to process it.
- Nette will call redirect.
…back to “start”…
1. Nette will create form component and send it to user. But form component will not be same (submited data changes it).
Now if i want to rebuild form component into independent AJAX component:
- Nette will create form component and send it to user.
- User will complete and submit(AJAX) form.
- Nette will create form component again to process it.
- Nette will call redirect(AJAX). But there is not any AJAX redirect!?!?
If i use redirect in 4. then whole page is reloaded :(
How to do AJAX request redirect?
- Vojtěch Dobeš
- Gold Partner | 1316
I am not sure what you mean by your post, but… AJAX requests usually don't
lead to redirect, that's their meaning – they're asynchronous. And yes, the
basic AJAX script from Addons redirects if the payload contains key
redirect
(Nette creates it in AJAX request when
$this->redirect(...
is called).
- redhead
- Member | 1313
If the redirect isn't needed (in most cases it isn't), the logic on the server side is usually done this way:
...
// some actions
...
if(!$this->isAjax()) {
$this->redirect('this'); // or any other destination
}
// for '$this' being a presenter in this case
Last edited by redhead (2012-05-13 11:04)
- mlha
- Member | 58
vojtech.dobes wrote:
I am not sure what you mean by your post, but… AJAX requests usually don't lead to redirect, that's their meaning – they're asynchronous. And yes, the basic AJAX script from Addons redirects if the payload contains key
redirect
(Nette creates it in AJAX request when$this->redirect(...
is called).
Heureka! That's solution. I have changed “AJAX Nette Framework plugin for jQuery”:
...
if (payload.redirect) {
//window.location.href = payload.redirect;
$.post($.nette.href = payload.redirect, $.nette.success);
return;
}
...
Thanks
Last edited by mlha (2012-05-15 21:23)