Lo uso para hacer una solicitud de recuperación de localhost. El javascript para eso estaba dentro de una etiqueta de script dentro del archivo index.html:
<!DOCTYPE html> <html lang="en"> <head> ... </head> <body> ... <script type="text/javascript"> ... var config = {} for (var file in guis) config[file] = guis[file].getValue() fetch('/one/two/three', {method: 'POST', body: JSON.stringify({type: type, config: config }) }) .then(response => response.json()) .then(function(test) { if ('href' in test) { setCookie("test_str", test['href'].split('http:',2)[1]) SomeFuction(); JumpTo(); } else { var alert_message = `Can't run test. ${test.detail}`; window.alert(alert_message); JumpTo(); } }) .catch(function (err) { var alert_message = `Can't run test: ${err}`; window.alert(alert_message); }) ... </script> </body> </html>Y funcionó. Pero después de un tiempo, moví todo el javascript (~ 800 líneas) a un archivo externo y lo importé como siempre:
<script src="./index.js"></script>y después de eso comencé a tener
POST http://172.17.0.2/one/two/three 400 (Bad Request)¿Cómo soluciono este error?