jcramalho

myPara

Nov 13th, 2017
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.79 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!-- jQuery: ex8.html -->
  3. <html>
  4. <head>
  5.     <script src="jquery-3.2.1.js"></script>
  6.     <script>
  7.         $(function(){
  8.             alert('Vou fazer o pedido da BD...')
  9.             $.getJSON("http://localhost:7777/getPara", function(data){
  10.                 alert('Recebi a BD: ' + JSON.stringify(data))
  11.                 $.each(data, function(ind, elem){
  12.                     $("#lista").append("<li id='" + elem.id + "'>" + elem.conteudo + "</li>")
  13.                 })
  14.             })
  15.               /*  .success(function(){})
  16.                 .error(function(err){
  17.                     alert("Erro: " + JSON.stringify(err))
  18.                 })
  19.                 .complete(function(){})*/
  20.  
  21.                 $("#lista > li").length + 1
  22.  
  23.             $("#adicionar").click(function(){
  24.                 $("#lista").append("<li>" + $("#texto").val() + "</li>")
  25.                
  26.                 alert('Vou atualizar a BD...\n')
  27.                 $.ajax({
  28.                     method: 'POST',
  29.                     url: 'http://localhost:7777/adPara',
  30.                     data: {id: "p" + ($("#lista > li").length),
  31.                            tempo: new Date().toString(),
  32.                            conteudo: $("#texto").val()}
  33.                 }).done(function( msg ) {
  34.                         alert( msg );
  35.                     })
  36.  
  37.                 $("#texto").val("")
  38.             })
  39.             $("#lista").on("click", "li", function(){
  40.                 $(this).remove()
  41.             })
  42.         });
  43.     </script>
  44. </head>
  45. <body>
  46.     <h1>MyPara</h1>
  47.     <form>
  48.         <label for="texto">Texto: </label>
  49.         <textarea id="texto"></textarea>
  50.         <br/>
  51.         <input type="button" value="Adicionar" id="adicionar"/>
  52.     </form>
  53.     <hr/>
  54.     <ol id="lista"></ol>
  55. </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment