Closed markuman closed 9 years ago
[W 2015/08/25 21:21:57] [web.lua] 405 Method Not Allowed POST /api (127.0.0.1) 1ms
....
function api:get()
try:
function api:post()
if you want to post from python with
>>> requests.post('http://localhost:8888/api', json=json.dumps({'Hello': 'Json'}))
@kernelsauce Thx, this works. Adding an api:options()
functions returns a 200 for XMLHttpRequest too.
But unfortunately I've no idea how to access the json data from turbo.lua now. Any hints?
reading the json from python works now, but not from javascript
-- http://localhost:8888/api
local api = class("api", turbo.web.RequestHandler)
function api:post()
local json = self:get_json(true)
for key,value in pairs(json) do print(key,value) end
print("from python")
end
function api:options()
local json = self:get_json(true)
print(json) -- this is nil
--for key,value in pairs(json) do print(key,value) end
print("from javascript")
end
The json value is nil (html file from first post). Any ideas what's the difference?
So finally I've figured out how the CORS stuff works and made an example. Maybe this is helpful for others too.
Thank you.
I'll try to receive some JSON data.
Trying to send from python results in a 405 error
The same happens when trying to send a JSON string from an HTML file (not served by turbo.lua)
But here turbo.lua results 405 with "options" error.
I guess CORS is needed and I need to setup some headers but don't know how. Any help?