jQuery的AJAX解析响应文本 [英] jquery ajax parse response text

查看:178
本文介绍了jQuery的AJAX解析响应文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定这是真的frusturating我,因为我在这之前一百次完成,这个时候它不工作。所以我知道我做错了什么,我只是不明白。

Ok this is really frusturating me because I've done this a hundred times before, and this time it isn't working. So I know I'm doing something wrong, I just can't figure it out.

我使用jQuery。获得程序到另一个文件中加载HTML。我不希望使用.load(),因为它总是会替换我加载内容到元素的孩子。

I am using the jQuery .get routine to load html from another file. I don't want to use .load() because it always replaces the children of the element I'm loading content into.

下面是我的。获得的要求:

Here is my .get request:

$(document).ready(function() {
    $.get('info.html', {}, function(html) {
        // debug code
        console.log($(html).find('ul').html());
        // end debug code
    });
});

文件'info.html里'是一个正确的DOCTYPE标准的XHTML文件,并在体内的唯一的事情是一系列UL的的,我需要访问。出于某种原因,查找功能是给我一个空值。

The file 'info.html' is a standard xhtml file with a proper doctype, and the only thing in the body is a series of ul's that I need to access. For some reason, the find function is giving me a null value.

在萤火虫,GET请求是显示适当的响应文本,当我运行

In firebug, the GET request is showing the proper RESPONSE text and when I run

console.log(html);

而不是当前的console.log行,我得到了在info.html整体作为输出,像我期望的那样。

Instead of the current console.log line, I get the whole info.html as output, like I would expect.

任何想法?

推荐答案

您不能在一个完整的XHTML文档拉。您只能处理&LT中存在的标记;身体GT; HTML文档。令人沮丧。剥去一切从info.html里,是不是你的&LT之内;身体GT; 标记并再次尝试

You cannot pull in an entire XHTML document. You can only handle tags that exist within the <body> of an html document. Frustrating. Strip everything from info.html that isn't within your <body> tag and try it again.

有解决这个问题的其他潜在方法 - 检查下面的#1相关信息,在此响应的基础

There are other potential ways around this issue - check below "Stackoverflow Related Items" at the base of this response.

从文档:(<一href="http://docs.jquery.com/Core/jQuery#htmlownerDocument">http://docs.jquery.com/Core/jQuery#htmlownerDocument)

HTML字符串不能包含的元素是无效的一个专区内,如   HTML,头部,身体,或标题元素。

"HTML string cannot contain elements that are invalid within a div, such as html, head, body, or title elements."

  • <一个href="http://stackoverflow.com/questions/1033460/simple-jquery-ajax-example-not-finding-elements-in-returned-html">Simple jQuery的AJAX例子中没有发现在返回的HTML
  • 元素
  • <一个href="http://stackoverflow.com/questions/1034881/what-is-the-best-practice-for-parsing-remote-content-with-jquery">What对于解析远程内容与jQuery的最佳实践?

Stackoverflow Related Items:

  • Simple jQuery ajax example not finding elements in returned HTML
  • What is the best practice for parsing remote content with jQuery?
  • 这篇关于jQuery的AJAX解析响应文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆