相关疑难解决方法(0)

使用jQuery解析远程内容的最佳实践是什么?

在jQuery ajax调用以检索整个XHTML文档之后,从结果字符串中选择特定元素的最佳方法是什么?也许有一个库或插件可以解决这个问题?

如果W3C规范中的div通常允许,jQuery只能选择存在于字符串中的XHTML元素; 因此,我很好奇选择喜欢的东西<title>,<script><style>.

根据jQuery文档:

http://docs.jquery.com/Core/jQuery#htmlownerDocument

HTML字符串不能包含div中无效的元素,例如html,head,body或title元素.

因此,既然我们已经确定jQuery没有提供这样做的方法,我将如何选择这些元素?例如,如果您可以告诉我如何选择远程页面的标题,那将是完美的!

谢谢,皮特

jquery html-parsing

35
推荐指数
2
解决办法
2万
查看次数

简单的jQuery ajax示例没有在返回的HTML中查找元素

我正在尝试学习jQuery的ajax函数.我有它的工作,但jQuery没有在返回的HTML DOM中找到元素.在与jquery相同的文件夹中,运行此页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <title>runthis</title>

    <script type="text/javascript" language="javascript" src="jquery-1.3.2.min.js"></script>

    <script tyle="text/javascript">
    $(document).ready(function(){
        $('input').click(function(){
            $.ajax({
                type : "GET",
                url : 'ajaxtest-load.html',
                dataType : "html",
                success: function(data) {

                alert( data ); // shows whole dom

                alert( $(data).find('#wrapper').html() ); // returns null

                },
                error : function() {
                    alert("Sorry, The requested property could not be found.");
                }
            });
        });
    });
    </script

</head>
<body>
    <input type="button" value="load" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

加载此页面"ajaxtest-load.html":

<!DOCTYPE html PUBLIC …
Run Code Online (Sandbox Code Playgroud)

ajax jquery parsing dom

11
推荐指数
2
解决办法
4万
查看次数

标签 统计

jquery ×2

ajax ×1

dom ×1

html-parsing ×1

parsing ×1