Posts /

Django 에서 fetch 를 이용한 요청

24 May 2018

개요

Example

var headers = new Headers();
var csrftoken = getCookie('csrftoken');
headers.append('X-CSRFToken', csrftoken);
headers.append('Accept', 'application/json, text/plain, */*');
headers.append('Content-Type', 'application/x-www-form-urlencoded');

fetch('/api',
      {
        method: 'post',
        headers: headers,
        credentials: 'include',
        body: JSON.stringify({
            is_man: true,
            numbers: [1,2,3],
            content: 'Content!!'
        })
      }
)
.then(_ => {
  // ...
}).catch(
  err => console.log(err)
);

Twitter Facebook Google+