Dieser Jquery-Code zeigt JSON-Daten innerhalb der Span html Eingabeelemente. Aber ich implementierte keine for-Schleife, um Array-Objekte von Filmgenres anzuzeigen.einfache Schleife durch JSON Api-Array JQuery
Im Moment ist es nur 0 Index des Arrays, aber ich will alles zeigen ..
$("#txt-movie-genres").val(json.genres[0].name)
$(document).ready(function() {
var url = 'http://api.themoviedb.org/3/',
mode = 'movie/',
movie_id,
key = '?api_key=e9dfeccf734a61b9a52d9d7660f0d0a1';
$('button').click(function() {
var input = $('#movie').val(),
movie_id = encodeURI(input);
$.ajax({
type: 'GET',
url: url + mode + movie_id + key,
async: false,
jsonpCallback: 'testing',
contentType: 'application/json',
dataType: 'jsonp',
success: function(json) {
// grab the span elements by ID and replace their text with the json text
// $("#movie-title").text(json.title);
$("#txt-movie-title").val(json.title)
$("#txt-movie-genres").val(json.genres[0].name)
console.dir(json);
},
error: function(e) {
console.log(e.message);
}
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="movie" type="text" /><button>Search</button>
<h1>Movie info:</h1>
<p>Movie title: <span id="span-movie-title"></span> </p>
<div class="input-group">
<input id="txt-movie-title" name="title" type="text" />
<div class="input-group-addon">
Movie Name
</div>
</div>
<div class="input-group">
<input id="txt-movie-genres" name="genres" type="text" />
<div class="input-group-addon">
Movie Genre
</div>
</div>
Haben Sie einen neuen Eingang für jedes Element des Arrays oder Anzeige Komma erstellen möchten getrennte Namen in einer einzigen Eingabe? – Alexander
ja! also das kann "Action, Adventure, Horror" usw. sein ... –