Unexpected token < in JSON at position 0
<p>If I do curl, the server returns an array of posts objects, like this:</p>
<pre><code>curl http://localhost/api/posts/
[
    {
        &quot;id&quot;: 7,
        &quot;target&quot;: {
            &quot;body&quot;: &quot;This is the body&quot;,
            &quot;title&quot;: &quot;Airbnb raising a reported $850M at a $30B valuation&quot;,
            &quot;user&quot;: {
                &quot;first_name&quot;: &quot;ben&quot;,
                &quot;last_name&quot;: &quot;jamin&quot;
            }
        }
    },
    {
        &quot;id&quot;: 11,
        &quot;target&quot;: {
            &quot;body&quot;: &quot;This is the body&quot;,
            &quot;title&quot;: &quot;Browsing the APISSS&quot;,
            &quot;user&quot;: {
                &quot;first_name&quot;: &quot;user&quot;,
                &quot;last_name&quot;: &quot;two&quot;
            }
        }
    }
]
</code></pre>
<p>I tried getting this using the fetch api:</p>
<pre><code>fromServer() {
    console.log('fromServer')
    var headers = new Headers();
    headers.append('Accept', 'application/json');
    let a = fetch('http://test.com/api/posts/', headers)
        .then(function(response) {
                if (response.status !== 200) {
                    console.log('There was a problem. Status Code: ' +  response.status);  
                    return;
                }

                response.json().then(function(data) {  
                    console.log(data);
                });  
            }  
        )  
        .catch(function(err) {  
            console.log('Fetch Error :-S', err);  
        });
}
</code></pre>
<p>But I am getting this error:</p>
<blockquote>
<p>Unexpected token &lt; in JSON at position 0</p>
<p>SyntaxError: Unexpected token &lt; in JSON at position 0</p>
</blockquote>
<p>How can I solve this problem? Could you please help me. Thank you.</p>