title: Using Fetch: SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
body: <p>I want to use the new Fetch in javascript to do an ajax request. This is the code I've written for that</p>
  
  <pre><code>// Example POST method implementation:
  var initial_data = {
    'id': 1,
    'model-name': 'Joke'
  };
  
  
  postData('/start-jokes', initial_data)
    .then(data =&gt; console.log(data)) // JSON from `response.json()` call
    .catch(error =&gt; console.error(error))
  
  function postData(url, data) {
    // Default options are marked with *
    return fetch(url, {
      body: JSON.stringify(data), // must match 'Content-Type' header
      cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
      credentials: 'same-origin', // include, same-origin, *omit
      headers: {
        'user-agent': 'Mozilla/4.0 MDN Example',
        'content-type': 'application/json'
      },
      method: 'POST', // *GET, POST, PUT, DELETE, etc.
      mode: 'cors', // no-cors, cors, *same-origin
      redirect: 'follow', // manual, *follow, error
      referrer: 'no-referrer', // *client, no-referrer
    })
    .then(response =&gt; response.json()) // parses response to JSON
  }
  </code></pre>
  
  <p>but it throws an error on load like so</p>
  
  <pre><code>SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
  </code></pre>
  
  <p>Trying it out on the console this is the response also of calling postData</p>
  
  <pre><code>Promise { &lt;state&gt;: "pending" }
  SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
  </code></pre>