Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. var data = { ...my contact JSON data... }
  2. var url = '/process/contact' // associated script = /src/routes/process/contact.js
  3.  
  4. fetch(url, {
  5. method: 'POST',
  6. body: JSON.stringify(data),
  7. headers: {
  8. 'Content-Type': 'application/json'
  9. }
  10. })
  11. .then(r => {
  12. r.json()
  13. .then(function(result) {
  14. // The data is posted: do something with the result...
  15. })
  16. })
  17. .catch(err => {
  18. // POST error: do something...
  19. console.log('POST error', err.message)
  20. })
  21.  
  22. export async function post(req, res, next) {
  23. /* Initializes */
  24. res.setHeader('Content-Type', 'application/json')
  25. /* Retrieves the data */
  26. var data = req.body
  27. // Do something with the data...
  28. /* Returns the result */
  29. return res.end(JSON.stringify({ success: true }))
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement