0
    <script type="text/javascript" src="http://www.google.com/jsapi?key=asedAWWefefI-43WqNAiw0XkfflwpU9zqkg">
            </script>
            <script type="text/javascript">
                google.load("jquery", "1.6.1");
            </script><script src="http://code.jquery.com/jquery-latest.js"></script>
            <script type="text/javascript">
                google.setOnLoadCallback(function()
                {...
}....

我的代码无法工作我猜这是上面代码的错。

整个代码

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script type="text/javascript" src="http://www.google.com/jsapi?key=AIzaSyDzbTUhnU2I-erwerwe3450XkfflwpU9zqkg">
        </script>
        <script type="text/javascript">
            google.load("jquery", "1.6.1");
        </script><script src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript">
            google.setOnLoadCallback(function()
            {
                $(function()
                {
                    $('#catalog').click(function(e)
                    {
                        e.preventDefault();
                        $.getJSON('books.php', function(data) {   
                            var book = "<h3>" + data.title + </h3>";                             
                            book += "<p>ISBN: " + data.isbn + "</p>";                                                
                            book += "<br/>Published Date: " + data.publishDate;
                            book += "<br/>Publisher: " + data.publisher;
                            var author = [];

                            $.each(data.authors, function(i, ov) {
                                authors.push(ov.name)
                            });

                            book += "<br/>Authors: " + authors.join(", ");
                            $('#resopnse').html(book);
                                                                                                                                            });
                    });
                });
            });                                              
        </script>
    </head>
    <body>
        <p><a id="catalog" href="">Retrieve book information</a></p>
        <div id="response"></div>
    </body>
</html>

当我单击链接时,它没有显示任何内容。我已经有一个 books.php 文件,其中包含一个格式化为具有 json 输出的数组。

更新

$.getJSON('books.php', function(data)
                        {
                            var book = "<h3>" + data.title + "</h3>";
                            book += "<p>ISBN: " + data.isbn + "</p>";
                            book += "<br/>Published Date: " + data.publishDate;
                            book += "<br/>Publisher: " + data.publisher;
                            var author = [];
                            $.each(data.authors, function(i, ov) { authors.push(ov.name) });
                            book += "<br/>Authors: " + authors.join(", ");
                            $('#response').html(book);

                        });

内部无法访问此功能。

4

1 回答 1

1

您的页面上存在 javascript 错误。你真的应该使用调试器。Chrome 开发工具非常好。如果您使用的是 chrome 或菜单 > 工具 > js 控制台,请按 [ctr][shift][j]

var book = "<h3>" + data.title + </h3>"; 

失踪 ”

于 2012-07-03T07:52:37.290 回答