I create a HTML file, that have this:
It's ok! Here is the code:
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<!-- Form part -->
<!-- bdd8feef -->
<!-- http://www.omdbapi.com/?i=tt0978762&apikey=bdd8feef -->
<!-- 1ca8226c006afb25adc4c816a2f8c184 -->
<!-- https://api.themoviedb.org/3/discover/movie?api_key=1ca8226c006afb25adc4c816a2f8c184 -->
<!-- https://api.themoviedb.org/3/search/movie?api_key=1ca8226c006afb25adc4c816a2f8c184&query=star+wars&page=1 -->
<!-- Just a button <button type="button">Click Me!</button> -->
<h2>HTML Forms</h2>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<form action="https://api.themoviedb.org/3/search/movie?api_key=1ca8226c006afb25adc4c816a2f8c184" method="post" target="_blank">
Buscar:<br>
<input type="text" name="query" value="black">
<br>
<!-- Last name:<br>
<input type="text" name="lastname" value="Mouse">-->
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
But that file, gets a JSON file, and I want to parse this way:
In another TAB (Chrome) or may be bellow in the same file, it ok.
I have the code to parse the JSON file (the same code where I create the second image)
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function() {
$.getJSON('https://api.themoviedb.org/3/search/movie?api_key=1ca8226c006afb25adc4c816a2f8c184&query=star+wars&page=1&language=en', function(data) {
$.each(data.results, function(i, f) {
var myPic = "https://image.tmdb.org/t/p/w185" + f.poster_path
var myBac = "https://image.tmdb.org/t/p/w92" + f.backdrop_path
var tblRow = "<tr>" + "<td>"
+ f.vote_count + "</td>" + "<td>"
+ f.id + "</td>" + "<td>"
+ f.video + "</td>" + "<td>"
+ f.vote_average + "</td>" + "<td>"
+ f.title + "</td>" + "<td>"
+ f.popularity + "</td>" + "<td>"
+ "<img src=" + myPic + ">" + "</td>" + "<td>"
+ f.original_language + "</td>" + "<td>"
+ f.original_title + "</td>" + "<td>"
+ f.genre_ids + "</td>" + "<td>"
+ "<img src=" + myBac + ">" + "</td>" + "<td>"
+ f.adult + "</td>" + "<td>"
+ f.overview + "</td>" + "<td>"
+ f.release_date + "</td>" + "</tr>"
$(tblRow).appendTo("#userdata tbody");
});
});
});
</script>
</head>
<body>
<div class="wrapper">
<div class="profile">
<table id= "userdata" border="2">
<thead>
<th>Total de votos</th>
<th>Id TMDB</th>
<th>Video</th>
<th>Promedio de votos</th>
<th>Titulo</th>
<th>Popularidad</th>
<th>Poster</th>
<th>Lenguaje original</th>
<th>Titulo Original</th>
<th>Generos</th>
<th>Background</th>
<th>Para Adultos</th>
<th>Sinopsis</th>
<th>Fecha de lanzamiento</th>
</thead>
<tbody>
</tbody>
</table>
</div>
</div>
</body>
</html>
What I need now it is to "combine" both files. When the user press the SUBMIT button appears the JSON file parsed, not just the code, in another tab, that is useless, i want to see the table. And i need to send the text in the INPUT field (Buscar) to create the search and create the table using that parameters, QUERY= and the word or words the user write in the input field.
The resulting string to send as a parameter will be:
https://api.themoviedb.org/3/search/movie?api_key=1ca8226c006afb25adc4c816a2f8c184&query=black


e.preventDefault(), than you need to serialize the form data, please take a look at .serialize(). The second parameter in$.getJSONis actually serialized data, take a look at .getJSON() method and also consider using $.ajax() method (which is better for understanding).