Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var data = { ...my contact JSON data... }
- var url = '/process/contact' // associated script = /src/routes/process/contact.js
- fetch(url, {
- method: 'POST',
- body: JSON.stringify(data),
- headers: {
- 'Content-Type': 'application/json'
- }
- })
- .then(r => {
- r.json()
- .then(function(result) {
- // The data is posted: do something with the result...
- })
- })
- .catch(err => {
- // POST error: do something...
- console.log('POST error', err.message)
- })
- export async function post(req, res, next) {
- /* Initializes */
- res.setHeader('Content-Type', 'application/json')
- /* Retrieves the data */
- var data = req.body
- // Do something with the data...
- /* Returns the result */
- return res.end(JSON.stringify({ success: true }))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement