リンクをクリックすると何らかの情報が表示されるように、リンクの 1 つを設定しようとしています。現在、リンクとリンクからの情報が一度に表示されます。最初にリンクを表示し、最初のリンクがクリックされた後にそれらのリンクからの情報を表示したいと思います。
ここに私のコードがあります、
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script >
$(document).ready(function($) {
// First link out of three
var url = 'https://www.sciencebase.gov/catalog
/items?parentId=504108e5e4b07a90c5ec62d4&max=60&offset=0&format=jsonp';
$.ajax({
type: 'GET',
url: url,
jsonpCallback: 'getSBJSON',
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
var linkBase = "http://www.sciencebase.gov/catalog/item/";
var link = "";
$.each(json.items, function(i,item){
link = linkBase + this.id
$('#sbItems').append('<li><b><a href="' + link + '">' +
this.title + '</a> - </b>' + this.summary + '</li>');
});
for (var i = 21; i < 22; i++) {
var urlId = json.items[i].id;
}
var itemLnkId = urlId;
//alert(itemLnkId);
$.ajax({
type: 'GET',
url: 'https://www.sciencebase.gov/catalog/itemLink/' +
itemLnkId + '?format=jsonp',
jsonpCallback: 'getSBJSON',
contentType: "application/json",
dataType: 'jsonp',
success: function(json) {
var linkBase = "http://www.sciencebase.gov/
catalog/item/";
var link = "";
$.each(json, function(i,item){
link = linkBase + this.relatedItemId
$('#sbItems').append('<li><a href="' +
link + '">' + this.title + '</a></li>');
});
for (var i = 19; i < 20; i++) {
var urlId = json.items[i].id;
}
var itemLnkId = urlId;
//alert(itemLnkId);
},
error: function(e) {
console.log(e.message);
}
});
},
error: function(e) {
console.log(e.message);
}
});
});
</script>
</head>
<body>
<p><em>This is a simple example of a basic HTML page that uses JQuery to call
items from ScienceBase in JSON format and output them on the page. It serves
to show how a basic web application can interact with dynamic ScienceBase
services. The code points out the one critical feature of such an application,
the use of a callback method in the Javascript to allow web pages on one domain
to call and render JSON from another domain (www.sciencebase.gov). The listing
below comes from a query for items under a particular ScienceBase parent item -
a set of project records from the USGS National Research Program. The listing
shows title with a link to the full project record in ScienceBase and summary
(first part of a full abstract). View source for code examples and inline
comments.</em></p>
<h3>Projects of the USGS Water National Research Program</h3>
<div class='wrapper'>
<ul id='sbItems'></ul>
</div>
</body>
</html>
ここにjsfiddleリンクがありますhttp://jsfiddle.net/XzRFu/ 助けてくれてありがとう!