<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);
});
此功能无法进入内部。
答案 0 :(得分:1)
您的网页上有一个javascript错误。你应该真的使用调试器。 Chrome开发工具非常棒。如果您使用的是铬或菜单,请按[ctr] [shift] [j]&gt;工具&gt; js console
var book = "<h3>" + data.title + </h3>";
缺少“