Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Untitled Document</title>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
- </head>
- <body>
- <button id="get-Json">Get JSON stuffs</button>
- <button id="get-html">Get Html stuffs</button>
- <p>
- </p>
- <script>
- $(document).ready(function(){//make sure page is done loading before executing code
- function getHTML() {
- // code to execute
- $.ajax({
- type:'GET',
- url:'/ajax/htmlajax.php',
- cache:false,
- dataType:'html',
- success:function( _response ) {
- console.log(_response);
- console.log( "This is an html call" );
- $("p").html(_response);
- },
- error:function( _xhr, _status, _error ) {
- console.log();
- console.log( "This is a failed html call" );
- console.log( "Error -> " + _xhr + " Status -> " + _status );
- }
- });
- }
- $( "button#get-html" ).on( "click", function() {
- getHTML();
- });
- })
- </script>
- <script>
- $(document).ready(function(){//make sure page is done loading before executing code
- function getJSON() {
- // code to execute
- $.ajax({
- type:'GET',
- url:'/ajax/jsonajax.php',
- cache:false,
- dataType:'json',
- success:function( _response ) {
- console.log(_response);
- console.log( "This is a Json call" );
- $("p").html(_response);
- },
- error:function( _xhr, _status, _error ) {
- console.log();
- console.log( "This is a failed Json call" );
- console.log( "Error -> " + _xhr + " Status -> " + _status );
- }
- });
- }
- $( "button#get-Json" ).on("click", function() {
- getJSON();
- })
- })
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement