V
V
Vladimir2019-11-13 06:15:36
JavaScript
Vladimir, 2019-11-13 06:15:36

How to fix this error in node.js SyntaxError: Unexpected token " in JSON at position 0?

Good morning. Please tell me where this symbol comes from and how to solve this problem in the root?
Here I am submitting a request

async function findCompany(url,id) {
        this.url = url
        this.id = id
        this.options = {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json'
          },
          body: JSON.stringify(this.id)				
        }

        const response = await fetch(this.url,this.options)
        const data = await response.json()

        if(data) {
          changeCompany('/control-company')
        }
        else {
          $('.company-data').css('display','flex')
        }

    }

And I get this from the server:
SyntaxError: Unexpected token " in JSON at position 0
at JSON.parse ()
at createStrictSyntaxError (C:\Users\History\Desktop\session\node_modules\body-parser\lib\types\json.js:158:10)
at parse (C:\Users\History\Desktop\session\node_modules\body-parser\lib\types\json.js:83:15)
at C:\Users\History\Desktop\session\node_modules\body-parser\lib\ read.js:121:18
at invokeCallback (C:\Users\History\Desktop\session\node_modules\raw-body\index.js:224:16)
at done (C:\Users\History\Desktop\session\node_modules \raw-body\index.js:213:7)
at IncomingMessage.onEnd (C:\Users\History\Desktop\session\node_modules\raw-body\index.js:273:7)
at IncomingMessage.emit(events. js:203:15)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2019-11-13
@HistoryART

Converted object to json object

JSON.stringify({id: this.id})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question