Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Untitled Document</title>
  6. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  7.  
  8. </head>
  9.  
  10. <body>
  11. <button id="get-Json">Get JSON stuffs</button>
  12.  
  13. <button id="get-html">Get Html stuffs</button>
  14.  
  15. <p>
  16. </p>
  17. <script>
  18.  
  19.  
  20.  
  21.  
  22. $(document).ready(function(){//make sure page is done loading before executing code
  23. function getHTML() {
  24. // code to execute
  25.  
  26. $.ajax({
  27.  
  28. type:'GET',
  29.  
  30. url:'/ajax/htmlajax.php',
  31.  
  32. cache:false,
  33.  
  34. dataType:'html',
  35.  
  36. success:function( _response ) {
  37. console.log(_response);
  38. console.log( "This is an html call" );
  39.  
  40. $("p").html(_response);
  41.  
  42. },
  43.  
  44. error:function( _xhr, _status, _error ) {
  45. console.log();
  46. console.log( "This is a failed html call" );
  47. console.log( "Error -> " + _xhr + " Status -> " + _status );
  48.  
  49. }
  50.  
  51. });
  52. }
  53. $( "button#get-html" ).on( "click", function() {
  54. getHTML();
  55. });
  56. })
  57.  
  58. </script>
  59. <script>
  60.  
  61. $(document).ready(function(){//make sure page is done loading before executing code
  62. function getJSON() {
  63. // code to execute
  64.  
  65. $.ajax({
  66.  
  67. type:'GET',
  68.  
  69. url:'/ajax/jsonajax.php',
  70.  
  71. cache:false,
  72.  
  73. dataType:'json',
  74.  
  75. success:function( _response ) {
  76. console.log(_response);
  77. console.log( "This is a Json call" );
  78.  
  79.  
  80. $("p").html(_response);
  81.  
  82. },
  83.  
  84. error:function( _xhr, _status, _error ) {
  85.  
  86. console.log();
  87. console.log( "This is a failed Json call" );
  88. console.log( "Error -> " + _xhr + " Status -> " + _status );
  89.  
  90. }
  91.  
  92. });
  93. }
  94. $( "button#get-Json" ).on("click", function() {
  95. getJSON();
  96. })
  97. })
  98. </script>
  99.  
  100.  
  101.  
  102. </body>
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement