Yes, you can make Ajax calls to web2py and get a response back -- and that
is independent of whether request.ajax is True. Here's the code used to set
request.ajax:
x_req_with = str(request.env.http_x_requested_with).lower()
request.ajax = x_req_with == 'xmlhttprequest'
So, web2py checks whether the request headers include "X-Requested-With:
XMLHttpRequest". Perhaps for some reason your Ajax call is not setting that
header. web2py will still respond to the request, but it won't set
request.ajax to True unless that header is there. You could either make
sure that header is set when the request is made, or add some other flag to
the request that your application can use to determine the type of request
(e.g., a GET or POST variable). See
http://stackoverflow.com/questions/1885847/jquery-no-x-requested-with-xmlhttprequest-in-ajax-request-header
.
Anthony
On Wednesday, August 1, 2012 4:42:15 PM UTC-4, simon wrote:
>
> I have a page served by a php application where a button makes an ajax
> call to a web2py controller. However when it arrives the request.ajax field
> is false and it then tries to redirect to the login page.
>
> Is it possible to make an ajax call to a web2py server from a non-web2py
> page and send the response back to the callling page? Am I doing it wrong?
>
--