mi HTML
<!DOCTYPE HTML5>
<html>
<head>
<title>Start Wars</title>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css" />
</head>
<body>
<ul class="navbar navbar-dark bg-dark">
<li class="nav-item">
<a class="nav-link active" href="index.html">Accueil</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Start Wars</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Nous</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Contact</a>
</li>
</ul>
<!--images banner-->
<div class="text-center">
<img src="images/stw.jpg" class="img-fluid" alt="Responsive image">
</div>
<div class="alert alert-dark text-center" role="alert">
<h2 class="name mb-0">Loading...</h2>
</div>
<div class="row">
</div>
</div>
<script type="text/javascript" src="node_modules/popper.js/dist/umd/popper.min.js"></script>
<script type="text/javascript" src="node_modules/jquery/dist/jquery.min.js"></script>
<script trype="text/javascript" src="node_modules/bootstrap/dist/js/bootstrap.js"></script>
<script type="text/javascript" src="js/query.js?var=14"></script>
</body>
</html>
Tengo una funcion JavaScript dentro de un archivo JS
$(document).ready(function() {
$.ajax({
url: 'https://swapi.co/api/people/1/?format=json',
type: 'GET',
dataType: 'JSON',
success: function(json) {
//console.log(json.name);
$("h2.name").text(json.name);
}
});
$.ajax({
url: 'https://swapi.co/api/people/?format=json',
type: 'GET',
dataType: 'JSON',
success: function(per) {
for (var i = 0; i < 6; i++) {
var a = $("<div onclick='data2('ddddd')' class='col-md-4'>" + per.results[i].name + "</div>");
$(".row").append(a);
//console.log(per.results[i].name);
}
}
});
});
function data2(nom) {
console.log(nom);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul class="navbar navbar-dark bg-dark">
<li class="nav-item">
<a class="nav-link active" href="index.html">Accueil</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Start Wars</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Nous</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">Contact</a>
</li>
</ul>
<!--images banner-->
<div class="text-center">
<img src="images/stw.jpg" class="img-fluid" alt="Responsive image">
</div>
<div class="alert alert-dark text-center" role="alert">
<h2 class="name mb-0">Loading...</h2>
</div>
<div class="row">
</div>
</div>