0

我想使用 jQuery mobile 和 JSON API 将我的 wordpress 博客文章显示为列表,但是当我执行程序时,我得到:

错误:语法错误,无法识别的表达式:div class="entry">undefined ...){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type| |"按钮"=...

这是我的代码:

索引.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">

    <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame
    Remove this if you use the .htaccess -->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <script src="css/style.css"></script>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    <script src="js/script.js"></script>
</head>
<body>

    <div id="blog" data-role="page">
    <div data-role="header" class="sys_hd" data-position="fixed" data-id="sys_header" >
        <h1>Sysads Posts</h1>
        </div><!-- header -->
        <div data-theme="c" data-role="content" id="postlist"> </div><!-- content -->
        <div data-role="footer" data-position="fixed" data-id="sys_footer" >
                    <div data-role="navbar" >
                <ul>
                    <li><a href="#blog" class="sys_ft">Home</a></li>
                    <li><a href="#blog" class="sys_ft">Disclaimer</a></li>
                </ul>
            </div><!-- navbar --> 
        </div><!-- footer --> 
    </div><!-- page -->
</body>
</html>

脚本.js:

/**
 * @author Admin
 */
$(document).ready((function(){
     url = 'http://hopexxx.com/category/daily-devotion/feed/';
        $.ajax({
        type: "GET",
        url: document.location.protocol + '//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=1000&callback=?&q=' + encodeURIComponent(url),
        dataType: 'json',
        error: function(){
            alert('Unable to load feed, Incorrect path or invalid feed');
        },
        success: function(xml){
            postlist = xml.responseData.feed.entries;
            console.log(postlist);
            $.each(postlist, function(data) {
                $('#postlist').append($('div class="entry">' + data.title + '</div>'));
            });
        }
    });
}));
4

1 回答 1

1

该代码$('div class="entry">' + data.title + '</div>')是 jQuery 表达式,它尝试查找与表达式匹配的元素,但从您尝试添加 html 的上下文中,而不是元素:

$.each(postlist, function(idx, data) {
    $('#postlist').append('<div class="entry">' + data.title + '</div>');
});

是的,正如 Damien 所写,html 也被破坏了。

于 2013-09-24T08:05:03.540 回答