Closed vespadj closed 2 years ago
... trying
for data in request:rawrdr() do
trace("request:rawrdr()", data)
end
It seem good
Yes, use this template code:
<?lsp
if "application/json" == request:header"Content-Type" then
local jparser = ba.json.parser()
local ok,table
for data in request:rawrdr() do
ok,table=jparser:parse(data)
if not ok or table then break end
end
trace(ok, table)
if ok and table then
response:json(table)
end
response:senderror(400, "Invalid JSON")
end
?>
<html>
<script>
const data={
weekdays:
["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
}
fetch(location.href, {
method: 'POST',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
}).then(res => res.json())
.then(res => console.log(res));
</script>
</html>
Please, provide an example for getting the body of the request when using fetch method.
I try
but the result is empty.
ECMA6 Fetch function is explained here.
Thanks