Flask with Fetch API and render_template - receive new rendered data Flask with Fetch API and render_template - receive new rendered data flask flask

Flask with Fetch API and render_template - receive new rendered data


  • you're not using fetch correctly at all
  • you're setting a cors response header in a request
  • mode: 'cors' is the default for cross origin requests, but
  • you're request is same origin, so why are you messing with CORS anything
  • no need to create that function or use async await

So

document.getElementById("search").addEventListener("click", function() {    let token = new FormData();    token.append('search', document.getElementById('search_place').value);    fetch('/stop', { method: 'POST', body: token })    .then(response => response.text())    .then(tables => $('.table').html(tables));});

but if you insist on using async/await

document.getElementById("search").addEventListener("click", async () => {    const token = new FormData();    token.append('search', document.getElementById('search_place').value);    const response = await fetch('/stop', { method: 'POST',body: token} );    const tables = await response.text();    $('.table').html(tables));});