In trunk, with a minor change that makes the type parameter optional and 
auto-detects ajax.

On Wednesday, 8 August 2012 08:21:33 UTC-5, Anthony wrote:
>
> Attached is a patch that enables client-side full-page redirects from Ajax 
> requests. It alters the redirect() function in http.py as well as adding an 
> event handler in web2py.js. With it, in a function called via Ajax, you can 
> do:
>
> def my_ajax_function():
>     if some_condition:
>         redirect(URL('default', 'other_function', extension=False), type=
> 'client')
>     return dict()
>
> In that case, redirect does not raise an HTTP(303). Instead, it raises an 
> HTTP(200) and sets a special "web2py-redirect-location" response header 
> with the redirect URL. On the client side, a jQuery.ajaxSuccess event 
> handler checks for that header on every successful Ajax request, and if the 
> header is there, it sets window.location to that URL, which loads the full 
> page in the browser window. Note, if redirecting from a function called 
> with the .load extension, you probably want to set extension=False when 
> constructing the redirect URL so the .load extension is not propagated to 
> the redirect.
>
> Eventually, we might consider adding a type='internal' option to the 
> redirect() function, which could generate a new internal request to the 
> redirect URL rather than sending a 303 to the server (this would have 
> nothing to do with Ajax -- just a way of speeding up regular server-side 
> redirects when you don't need the browser to receive a new URL with the 
> redirect).
>
> Anthony
>
> On Wednesday, August 8, 2012 4:58:44 AM UTC-4, mweissen wrote:
>>
>> Any solution so far?
>>
>> 2012/7/29 Martin Weissenboeck <mwei...@gmail.com>
>>
>>> Thank you!
>>>
>>>
>>> 2012/7/28 Massimo Di Pierro <massimo....@gmail.com>
>>>
>>>> I will take a patch. ;-)
>>>>
>>>>
>>>> On Friday, 27 July 2012 16:54:51 UTC-5, mweissen wrote:
>>>>>
>>>>> Hallo Johann,
>>>>>
>>>>> I have tried your proposal - yes, this "workaround" does the job and I 
>>>>> think I will use it.
>>>>> But I am surprised that there is not simple solution. Or does nobody 
>>>>> else want to get rid the "load"?
>>>>>
>>>>> 2012/7/27 Johann Spies <johann...@gmail.com>
>>>>>
>>>>>> Hallo Martin, 
>>>>>>
>>>>>> In stead of redirecting, I am using this script in the view:
>>>>>>
>>>>>> <script type="text/javascript">
>>>>>>     jQuery(document).ready(**function() {
>>>>>>                           
>>>>>> jQuery($(":input:submit:last")**.addClass('gaanvoort'));
>>>>>>
>>>>>>                           jQuery($("input.gaanvoort").**click(
>>>>>>                               function() {
>>>>>>                                   window.location = 
>>>>>> "/init/articles/add_article";
>>>>>>
>>>>>>
>>>>>>
>>>>>>                                   }));
>>>>>>
>>>>>>
>>>>>>
>>>>>>                            });
>>>>>>  </script>
>>>>>>  
>>>>>> and then use session variables on the destination.
>>>>>>
>>>>>> Regards
>>>>>> Johann
>>>>>>
>>>>>> -- 
>>>>>> Because experiencing your loyal love is better than life itself, 
>>>>>> my lips will praise you.  (Psalm 63:3)
>>>>>>
>>>>>

-- 



Reply via email to