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

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

      1. 来自 .ajax() 调用的数据的 jQuery .find() 正在返回“[object Object]".

        时间:2023-10-02

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

              <tbody id='cZK8b'></tbody>
                <tfoot id='cZK8b'></tfoot>

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

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

                • 本文介绍了来自 .ajax() 调用的数据的 jQuery .find() 正在返回“[object Object]".而不是 div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  试图在 .ajax() 使用 .find().不幸的是,alert(result) 不返回 div#result.

                  这是我的代码:

                  $.ajax({网址:网址,缓存:假,成功:功能(响应){结果 = $(response).find("#result");警报(响应);//按预期工作(返回所有 html)警报(结果);//返回 [object 对象]}});

                  解决方案

                  具体回答您的问题,它似乎工作正常.您说它返回 [object Object],这就是 jQuery 使用 find("#result") 方法返回的内容.它返回一个匹配 find 查询的 jQuery 元素.

                  尝试获取该对象的属性,例如 result.attr("id") - 它应该返回 result.

                  <小时>

                  一般来说,这个答案取决于 #result 是否是顶级元素.

                  如果#result是顶级元素,

                  <div id="结果"><span>文本</span></div><div id="其他顶级元素"></div>

                  find() 将不起作用.相反,使用 filter():

                  var $result = $(response).filter('#result');

                  如果#result不是顶级元素,

                  <div id="结果"><span>文本</span></div></div>

                  find() 会起作用:

                  var $result = $(response).find('#result');

                  Trying to find div element with id="result" in returned data from .ajax() using .find(). Unfortunately, alert(result) doesn't return div#result.

                  Here is my code:

                  $.ajax({
                      url: url, 
                      cache: false,
                      success: function(response) {
                          result = $(response).find("#result");
                          alert(response); // works as expected (returns all html)
                          alert(result); // returns [object Object]
                      }
                  });
                  

                  解决方案

                  To answer your question specifically, it seems to be working correctly. You said that it returns [object Object], which is what jQuery will return with the find("#result") method. It returns a jQuery element that matches the find query.

                  Try getting an attribute of that object, like result.attr("id") - it should return result.


                  In general, this answer depends on whether or not #result is the top level element.

                  If #result is the top level element,

                  <!-- #result as top level element -->
                  <div id="result">
                    <span>Text</span>
                  </div>
                  <div id="other-top-level-element"></div>
                  

                  find() will not work. Instead, use filter():

                  var $result = $(response).filter('#result');
                  

                  If #result is not the top level element,

                  <!-- #result not as top level element -->
                  <div>
                    <div id="result">
                      <span>Text</span>
                    </div>
                  </div>
                  

                  find() will work:

                  var $result = $(response).find('#result');
                  

                  这篇关于来自 .ajax() 调用的数据的 jQuery .find() 正在返回“[object Object]".而不是 div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                    <tfoot id='xBZjW'></tfoot>

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

                            <tbody id='xBZjW'></tbody>