0
import React, { useEffect } from 'react'
import Head from "next/head"

export default function submit() {
    const handleForm = async event => {
        event.preventDefault()
    
        const res = await fetch('http://localhost:4000/api/bot/submitted', {
          body: JSON.stringify({
           ...
          }),
          headers: {
            'Content-Type': 'application/json'
          },
          method: 'POST'
        })
    
        const result = await res.json()
    }

    return (        
        <div>
            <form onSubmit={ handleForm }>
                ...
            </form>
        </div>
    )
}

i checked my backend but it didnt send the request to the backend, when i submit my form it says "failed to fetch"

Onii-Chan
  • 57
  • 1
  • 6
  • Does it show any error on dev tools in browser? – Bharat Jul 20 '21 at 09:17
  • "acces to http://.. has been blocked by CORS" – Onii-Chan Jul 20 '21 at 09:26
  • @Onii-Chan On what framework is your backend? In Express, you can use the [`cors`](http://expressjs.com/en/resources/middleware/cors.html) middleware. – brc-dd Jul 20 '21 at 11:04
  • 1
    Does this answer your question? [How does Access-Control-Allow-Origin header work?](https://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work) – juliomalves Jul 20 '21 at 17:18

0 Answers0