【问题标题】:how to parse the values inside of an object that comes from an ajax get request?如何解析来自ajax get请求的对象内部的值?
【发布时间】:2021-02-19 21:06:12
【问题描述】:

我有一个从 Ajax 获取请求中获取的变量对象类型,我想使用该对象内的表行中的值。

$.get(url2, function (responseGET) {
      var responseGETHtml2 = $(responseGET).find(".data-item-form form.form");
 
      console.log("responseGETHtml2", responseGETHtml2);

输出:

k.fn.init [form.form.default-form, prevObject: k.fn.init(91)]
0: form.form.default-form
length: 1
prevObject: k.fn.init(91) [text, meta, text, title, text, comment, comment, comment, meta, text, meta, text, meta, text, link, text, link, text, link, text, link, text, link, text, link, text, link, text, link, text, link, text, link, text, link, text, link, text, link, text, link, text, header, article, span, span, span, span, span, span, span, span, span, span, span, span, span, span, span, span, span, span, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, script, text]
__proto__: Object(0)

【问题讨论】:

    标签: javascript jquery ajax object parsing


    【解决方案1】:

    使用.html()查看元素的HTML内容。

    console.log("responseGETHtml2", responseGETHtml2.html());
    

    【讨论】:

    • 它有效,但是我如何在不使用拆分的情况下获取表内的值?
    • 使用responseGETHtml2.find("tr") 获取表格行,然后遍历它们。就像在 DOM 上操作一样。
    • 我不知道它是如何工作的。当我执行 $(responseGETHtml2).find("tr") 时,我得到与 start 相同的结果:k.fn.init [prevObject: k.fn.init(19)]
    • 就像在答案中一样,您必须使用.html().text() 来获取元素的内容。您正在记录 jQuery 对象本身。
    • 对不起我的无知但是当我做 console.log("tr", $(responseGETHtml2).find("tr").html()); ,我得到:未定义
    猜你喜欢
    • 1970-01-01
    • 2015-09-02
    • 1970-01-01
    • 1970-01-01
    • 2020-10-14
    • 2021-08-20
    • 1970-01-01
    • 2016-08-26
    • 1970-01-01
    相关资源
    最近更新 更多