'Why I got reloading with a POST to json-server
I'm testing the json-server package with the following HTML, so my problem is the next one:
My page reload after I click on My button
I'm trying with a POST request but I don't understand why after the POST, my page reloads.
<script>function test(){
fetch('http://localhost:3000/sessions/',{
method:'POST',
mode:'no-cors'
})
console.log('Success')
}
</script>
<body>
<div id="container"></div>
<button type="button" onclick="test()">My button</button>
</body>
Even, when I change the request method to GET, the page doesn't reload when I click on that button.
I think that the problem is related to json-server because when I make POST request to other APIs, my page doesn't reload, but I'm not sure why. Somebody could help me
Solution 1:[1]
Do you use the Live Server extension? For some weird reason it causes all requests but 'GET' to reload the page. Try disabling that and you shoukd be fine.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Angelos Barmpoutis |