Hello all,
My javascript is making a CORS call to web2py; wherein I have set the
following in my controller:
response.headers['Content-Type'] = 'application/json; charset=utf-8'
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Max-Age'] = 86400
response.headers['Access-Control-Allow-Headers'] = 'Origin'
response.headers['Access-Control-Allow-Methods'] = 'GET'
response.headers['Access-Control-Allow-Credentials'] = 'true'
Have also set the necessary settings in my Javascript client to make the
CORS work.
In my controller method:
def get_data():
data = get_data_from_datastore()
if data:
return data
else:
raise HTTP(404)
When there is data to return, things work fine. The CORS request goes
through fine, and the JS client receives a HTTP 200 response.
When there is no data, the server code raises a 404, with the intention of
letting the JS client know that there is no data for this request. But
then, there is an error seen on the client side: "XMLHttpRequest cannot
load http://127.0.0.1:8000/a/c/get_data?q='23'. No
'Access-Control-Allow-Origin' header is present on the requested resource.
Origin 'http://origin.server.com' is therefore not allowed access. The
response had HTTP status code 404."
Not sure what is happening here. Is the raise HTTP() removing/resetting the
response.headers that I set?
Any suggestions?
Thank you,
Kiran
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.