<form id='result2'></form>
<script>
  fetch('/getAudio', { method: 'POST' })
    .then(response => response.json())
    .then(data => {
      document.getElementById('result2').innerHTML = data['Rescoring_result'];
    })
    .catch(error => console.error(error));
</script>
<p>以下是已经调试过的代码:</p>
<pre><code class="language-html">&lt;form id='result2'&gt;&lt;/form&gt;
&lt;script&gt;
  fetch('/getAudio', { method: 'POST' })
    .then(response =&gt; response.json())
    .then(data =&gt; {
      document.getElementById('result2').innerHTML = data['Rescoring_result'];
    })
    .catch(error =&gt; console.error(error));
&lt;/script&gt;
</code></pre>
<p>主要的修改点有:</p>
<ol>
<li>取消了多余的反斜杠</li>
<li>去掉了多余的 <code>JSON.parse()</code>,因为 <code>response.json()</code> 已经返回解析后的 JSON 对象</li>
<li>直接使用 <code>data['Rescoring_result']</code>,不再需要将其赋值给一个中间变量</li>
</ol>
JavaScript 代码调试:使用 Fetch API 获取 JSON 数据并渲染

原文地址: https://www.cveoy.top/t/topic/lAQU 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录