Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Send Post Fetch REquest With Django

function getCookie(name) {
        let cookieValue = null;
        if (document.cookie && document.cookie !== '') {
            const cookies = document.cookie.split(';');
            for (let i = 0; i < cookies.length; i++) {
                const cookie = cookies[i].trim();
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) === (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
    const csrftoken = getCookie('csrftoken');

async    function send()
  {
let r =      await fetch('/blog/third', {method: 'POST', 
                                         credentials: 'same-origin',
                                         headers:{'Accept': 'application/json',   
                                         'X-Requested-With': 'XMLHttpRequest', 
                                         'X-CSRFToken': csrftoken}
                                        });
let res = await r.json();
console.log(res.text);
    }
    
#as you can see, it's much more complicated than GET :)
#but in reality this is probably what you will end up doing
Comment

Send Fetch Request Django(Get Method)

async    function send()
    {

let r =      await   fetch('/blog/third', {method: "GET"});
let res = await r.json();
console.log(res.text);

    }
Comment

PREVIOUS NEXT
Code Example
Javascript :: generate random string with javascript 
Javascript :: store images in mongoose 
Javascript :: delete axios token 
Javascript :: generate numbers from 1 to 100 to array 
Javascript :: check object is null empty or undefined 
Javascript :: jquery hide select option 
Javascript :: javascript slice vs splice 
Javascript :: javascript remove all element in array 
Javascript :: jquery get all input name and values and submit 
Javascript :: text.toUpperCase is not a function 
Javascript :: get value of hidden type field 
Javascript :: get only numbers from string 
Javascript :: remove duplicates multidimensional array javascript 
Javascript :: nested array filter 
Javascript :: foreach index 
Javascript :: radio button getelementsbyname 
Javascript :: add toolbar button quill.js 
Javascript :: clear interval js 
Javascript :: why does my form reload the page? html js 
Javascript :: javascript insert text in textarea at cursor position 
Javascript :: javascript url pas array 
Javascript :: base href 
Javascript :: debouncing 
Javascript :: change href javascript 
Javascript :: console.log json shopify 
Javascript :: A simple static file server built with Node.js 
Javascript :: anagram program in javascript 
Javascript :: i want to redirect to main page from iframe javascript 
Javascript ::  
Javascript :: react native navigation remove top header screen 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =