Advertisement
nicolas-chuet

scriptavecgetcorrige.js

Mar 27th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. //declaration de JQUERY en javascript, pas le choix
  2. const scriptJquery = document.createElement("script");
  3. scriptJquery.setAttribute("src","https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js");
  4. document.head.appendChild(scriptJquery);
  5. var modalContent;
  6.  
  7. //une fois le Jquery chargé, on ajoute le reste en JQUERY
  8. scriptJquery.onload = function() {
  9.  
  10. //Ajouter bootstrap js et css
  11. $('head').append('<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css" type="text/css" />');
  12. $('head').append('<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" />');
  13.  
  14. //insertion des éléments
  15. $('body').append('<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">Launch demo modal</button>');
  16.  
  17.  
  18. $.get(
  19. 'http://modal.local/modal1.html', // Le fichier cible côté serveur.
  20. getresponse, // Nous renseignons uniquement le nom de la fonction de retour.
  21. 'html' // Format des données reçues.
  22. );
  23.  
  24. function getresponse(data){
  25. modalContent = data;// Du code pour gérer le retour de l'appel AJAX.
  26. $('body').append(modalContent);
  27.  
  28. }
  29.  
  30.  
  31.  
  32. // $(document).ready(function() { setTimeout(openModal,1000) });
  33.  
  34. };
  35.  
  36. function openModal(){
  37. $('#exampleModalCenter').modal('toggle')
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement