<small id='BVDXI'></small><noframes id='BVDXI'>

  • <tfoot id='BVDXI'></tfoot>
    <legend id='BVDXI'><style id='BVDXI'><dir id='BVDXI'><q id='BVDXI'></q></dir></style></legend>
      <bdo id='BVDXI'></bdo><ul id='BVDXI'></ul>

      1. <i id='BVDXI'><tr id='BVDXI'><dt id='BVDXI'><q id='BVDXI'><span id='BVDXI'><b id='BVDXI'><form id='BVDXI'><ins id='BVDXI'></ins><ul id='BVDXI'></ul><sub id='BVDXI'></sub></form><legend id='BVDXI'></legend><bdo id='BVDXI'><pre id='BVDXI'><center id='BVDXI'></center></pre></bdo></b><th id='BVDXI'></th></span></q></dt></tr></i><div id='BVDXI'><tfoot id='BVDXI'></tfoot><dl id='BVDXI'><fieldset id='BVDXI'></fieldset></dl></div>

        jQuery $.ajax 或 $.load 是否允许 responseType arrayBuffe

        时间:2023-10-13
      2. <i id='oIZgM'><tr id='oIZgM'><dt id='oIZgM'><q id='oIZgM'><span id='oIZgM'><b id='oIZgM'><form id='oIZgM'><ins id='oIZgM'></ins><ul id='oIZgM'></ul><sub id='oIZgM'></sub></form><legend id='oIZgM'></legend><bdo id='oIZgM'><pre id='oIZgM'><center id='oIZgM'></center></pre></bdo></b><th id='oIZgM'></th></span></q></dt></tr></i><div id='oIZgM'><tfoot id='oIZgM'></tfoot><dl id='oIZgM'><fieldset id='oIZgM'></fieldset></dl></div>
          <tbody id='oIZgM'></tbody>
        <tfoot id='oIZgM'></tfoot>

            • <bdo id='oIZgM'></bdo><ul id='oIZgM'></ul>
              • <legend id='oIZgM'><style id='oIZgM'><dir id='oIZgM'><q id='oIZgM'></q></dir></style></legend>

                  <small id='oIZgM'></small><noframes id='oIZgM'>

                  本文介绍了jQuery $.ajax 或 $.load 是否允许 responseType arrayBuffer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我开始使用 Web Audio API,只是想知道是否可以使用 jQuery 的 $.ajax 或 $.load 函数来生成接收音频数据的 XMLHttpRequest.$.ajax 或 $.load 是否支持 responseType=arrayBuffer?

                  I'm getting started with the Web Audio API and just wondering if it's possible to use jQuery's $.ajax or $.load functions to make the XMLHttpRequest that receives the audio data. Do $.ajax or $.load support responseType=arrayBuffer?

                  好的,这就是我目前所拥有的:

                  Ok, so here's what I have so far:

                  function loadAudio() {
                      $.ajax({
                              url: sourceUrl
                          }).done(function(response){
                              return response;
                          })
                      }
                  

                  但我需要返回一个 ArrayBuffer.那么如何将响应转换为 ArrayBuffer 呢?

                  but I need to return an ArrayBuffer. So how do I convert the response into an ArrayBuffer?

                  推荐答案

                  关于你的问题,jQuery 好像还不支持.在按照我下面的建议使用它之前,请考虑检查该功能是否可用.

                  About your question, it seems jQuery does not support it yet. Before using it as I suggested below, consider checking if the feature is available.

                  使用 XHTMLRequest,您可以欺骗您的服务器并从服务器接收表示您想要的字节的二进制字符串.效果很好.

                  With XHTMLRequest, you can trick your server and receive a binary string representing the bytes you want from the server. It works perfectly.

                  var xhr = new XMLHttpRequest();
                  xhr.open('GET', '/your/audio/file.wav', true);
                  
                  // Here is the hack
                  xhr.overrideMimeType('text/plain; charset=x-user-defined');
                  
                  xhr.onreadystatechange = function(event) {
                    if ( this.readyState == 4 && this.status == 200 ) {
                      var binaryString = this.responseText;
                  
                      for (var i = 0, len = binaryString.length; i < len; ++i) {
                        var c = binaryString.charCodeAt(i);
                        var byte = c & 0xff; //it gives you the byte at i
                        //Do your cool stuff...
                  
                      }
                    }
                  };
                  
                  xhr.send();
                  

                  它有效,它很常见......但是......它仍然是一个黑客.

                  It works, it's common... but... it is still a hack.

                  使用 XHTML 请求级别 2,您可以将 responseType 指定为 'arraybuffer' 并实际接收 ArrayBuffer.它要好得多.问题是检查您的浏览器是否支持此功能.

                  With XHTML Request Level 2, you can specify the responseType as 'arraybuffer' and receive the ArrayBuffer actually. It is much nicer. The problem is to check if your browser support this feature.

                  var xhr = new XMLHttpRequest();
                  xhr.open('GET', '/your/audio/file.wav', true);
                  xhr.responseType = 'arraybuffer';
                  
                  xhr.onload = function(e) {
                    if (this.status == 200) {
                      //Do your stuff here
                    }
                  };
                  
                  xhr.send();
                  

                  希望我能帮上忙.

                  这篇关于jQuery $.ajax 或 $.load 是否允许 responseType arrayBuffer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Chrome 打包应用程序中通过 XHR 加载本地内容 下一篇:try-catch 不适用于 XMLHTTPRequest

                  相关文章

                  最新文章

                1. <legend id='Z1Aj4'><style id='Z1Aj4'><dir id='Z1Aj4'><q id='Z1Aj4'></q></dir></style></legend>
                  <tfoot id='Z1Aj4'></tfoot>

                  <small id='Z1Aj4'></small><noframes id='Z1Aj4'>

                    <bdo id='Z1Aj4'></bdo><ul id='Z1Aj4'></ul>
                      <i id='Z1Aj4'><tr id='Z1Aj4'><dt id='Z1Aj4'><q id='Z1Aj4'><span id='Z1Aj4'><b id='Z1Aj4'><form id='Z1Aj4'><ins id='Z1Aj4'></ins><ul id='Z1Aj4'></ul><sub id='Z1Aj4'></sub></form><legend id='Z1Aj4'></legend><bdo id='Z1Aj4'><pre id='Z1Aj4'><center id='Z1Aj4'></center></pre></bdo></b><th id='Z1Aj4'></th></span></q></dt></tr></i><div id='Z1Aj4'><tfoot id='Z1Aj4'></tfoot><dl id='Z1Aj4'><fieldset id='Z1Aj4'></fieldset></dl></div>