Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>POST y GET</title>
- </head>
- <body>
- <input type="text" name="nombre">
- <button>Enviar</button>
- <div class="muestra"></div>
- <script src="js/jquery.js"></script>
- <script>
- $(document).ready(function(){
- $("button").click(function(){
- //ajax simplificado
- /*
- $.post('http://localhost/cursos-www/ejercicios-curso-html5/ejercicios-jquery/rest.php',
- {nombre:$("input[name='nombre']").val()},
- function(data){
- alert(data);
- });
- */
- $.get('https://jsonplaceholder.typicode.com/posts',function(data){
- var html = "";
- $.each( data, function( llave, valor ) {
- //console.log( "Titulo: "+valor.title +", Body: "+ valor.body );
- html += "<h1>"+valor.title+"</h1>";
- html += "<p>"+valor.body+"</p>";
- });
- $(".muestra").html(html);
- });
- });
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement