degath degath - 2 months ago 6
Ajax Question

from one html file to another in loop html/jquery/js/ajax

maybe its easy, but I'm really beginner in front end.
Right now I've got:


  • 1 main html file(index.html)

  • 1 javascript file(something.js)

  • 2nd html file(something.html)



Main html:

<!DOCTYPE html>
<html lang="en">
<head>
<link href="css/bootstrap.min.css" rel="stylesheet">
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/something.js"></script>
</head>
<body>
<div class="container-fluid well-lg">
<div id="targetInformation">

</div>
</div>
</body>
<html>


2nd html:

<div class=" col-md-4 col-sm-6 col-xs-12">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
Some title
</h3>
</div>
<div class="panel-body">
<p>info1</p>
<p>info2</p>
<p>info3</p>
</div>
</div>
</div>


I want to:
create a loop in js/jquery/ajax to load 6 times what is inside 2nd html to a first html.
One thing I know is that I need to use $.get().
Any ideas how my js should look like, and how to use js in a div?
Thanks :)
Tried to find a solution, but didnt found, sorry for bothering

ps. I didnt send you my something.js, because its empty, really got no idea how to start.

Answer

Try This -

$(function () {
            $.get("something.html", function (data) {
              for(let i =0; i<6; i++)
                 {
                    $("#targetInformation").append(data);
                 }

            });
        });
Comments