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

    <tfoot id='Hqq09'></tfoot>
      <bdo id='Hqq09'></bdo><ul id='Hqq09'></ul>
  2. <small id='Hqq09'></small><noframes id='Hqq09'>

      XMLHttpRequest responseType = "json";给出错误 S

      时间:2023-10-13

          <tfoot id='IsZzw'></tfoot>

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

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

              2. 本文介绍了XMLHttpRequest responseType = "json";给出错误 SYNTAX_ERR: DOM Exception 12的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我无法将 XHR responseType 设置为json".如果我将其保留为空字符串 xml.responseType = ""; 会正常工作,但是当我将其设置为json"时,我会收到控制台错误消息 SYNTAX_ERR: DOM Exception 12.

                I am having trouble setting the XHR responseType to "json". It works fine if I leave it an empty string xml.responseType = ""; but when I set it to "json" I get the console error message SYNTAX_ERR: DOM Exception 12.

                .js 文件:

                var xml = new XMLHttpRequest();
                xml.open("GET", "test.php", true);
                xml.responseType = "json";
                xml.send();
                

                .php 文件:

                <?php
                $foo = "{"key1":"val1", "key2":"val2"}";
                echo $foo;
                ?>
                

                不知道发生了什么……有什么想法吗?

                Not sure what's going on.. Any ideas?

                推荐答案

                responseType 对象的 XMLHttpRequest 属性已添加到其新变体 XMLHttpRequest Level 2 并且包含在 HTML 5 中,我不确定所有浏览器都支持这种方法,所以您使用的浏览器可能没有实现该方法

                responseType property for XMLHttpRequest object is added in its new variant XMLHttpRequest Level 2 and which is included in HTML 5, i am not sure all browsers support this method so it could be possible that you are using a browser which doesn't implement that method

                您可以使用以下代码来获取所需格式的数据,而不是使用 responseType

                instead of using responseType you can use following code to get data in desired format

                 var xml = new XMLHttpRequest();
                 xml.open("GET", "test.php", true);
                
                 xml.onreadystatechange = function() {
                   if (xml.readyState != 4)  { return; }
                
                   var serverResponse = JSON.parse(xml.responseText);
                 };
                
                 xml.send(null);
                

                这篇关于XMLHttpRequest responseType = "json";给出错误 SYNTAX_ERR: DOM Exception 12的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何强制程序等到 JavaScript 中的 HTTP 请求完成? 下一篇:我怎样才能让 XHR.onreadystatechange 返回它的结果?

                相关文章

                最新文章

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

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

              3. <tfoot id='jPBoB'></tfoot>
                • <bdo id='jPBoB'></bdo><ul id='jPBoB'></ul>