Zhi Xuan Lim
Zhi Xuan Lim

Reputation: 3

React native JSON Parse error:Unrecognized token '<'

i want to ask json parse api link must be hosting under by https? i got this error because my hosting was not secure? anyone know this problem? this is my code:

fetch('http://xxx.xxx.x.xx/reactnative/register.php', {
            method: 'post',
            header:{
                'Accept': 'application/json',
                'Content-type': 'application/json'
            },
            body:JSON.stringify({
                name: userName,
                email: userEmail,
                password: userPassword,
            })

but my link cant run https:// on the browser Is this cause me cant parse the data to the link?

Upvotes: 0

Views: 7661

Answers (1)

Franklin Farahani
Franklin Farahani

Reputation: 156

This is most likely caused by the response you're receiving being an html page. Make sure your server is set up to receive the information you're trying to send in JSON form. You could try sending your data in application/x-www-form-urlencoded format (in case that's how the server is expecting the data) like so:

body: `name=${userName}&email=${userEmail}&password=${userPassword}`

Upvotes: 2

Related Questions