HTML Form 和 Fetch API:发送 POST 请求并解析 JSON 响应
<form id='result2'>方法2</form>
<script>
fetch('http://127.0.0.1:9999/getAudio', { method: 'POST' })
.then(response => response.json())
.then(response => document.getElementById('result2').innerHTML = response['Rescoring_result'])
.catch(error => console.error(error))
</script>
<p>这段代码的作用是发送一个 POST 请求到指定的 URL (http://127.0.0.1:9999/getAudio),并使用 fetch() 方法获取响应。然后,使用 response.json() 方法将响应转换为 JavaScript 对象,将对象中的 'Rescoring_result' 属性的值插入到 id 为 'result2' 的表单元素中。如果发生错误,会在控制台中记录错误。</p>
原文地址: https://www.cveoy.top/t/topic/lBfg 著作权归作者所有。请勿转载和采集!