Advertisement
gundambison

coba ajax 2x

Aug 11th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. <?php
  2. if(isset($_POST['username'])){
  3.   $ret=array($_POSTS);
  4.  
  5.  
  6.  
  7.   die(json_encode($ret));
  8. }
  9.  
  10. ?>
  11. <script src='../media/js/jquery1.11.3.js'></script>
  12. <button type='button' onclick='checkLogin()' >test</button>
  13.  
  14.  
  15. <script>
  16. function checkLogin()
  17. {
  18. console.log('tunggu 2 detik');
  19. var datax = {username:'contoh', password:'contoh'}
  20. //$(selectorform).serialize();
  21.         console.log('check login');
  22.         var request = $.ajax({
  23.                   url: "?act=34",
  24.                   type: "POST",
  25.                   data: datax ,
  26.                   dataType: "json"
  27.         });
  28.          
  29.         request.success(function(ret) {
  30.            console.log('berhasil');
  31.            console.log(ret);
  32.        status=true;
  33.            
  34.         });
  35.          
  36.         request.fail(function(jqXHR, textStatus) {
  37.           alert( "Request failed: " + textStatus );
  38.           status=false;
  39.         });
  40.  
  41.         setTimeout(function() {
  42.  
  43.        
  44. //===========ajax 2
  45.     datax2={username:'contoh',status:'OK'}
  46.     var request2 = $.ajax({
  47.                   url: "?act=35",
  48.                   type: "POST",
  49.                   data: datax2 ,
  50.                   dataType: "json"
  51.         });
  52.     request2.success(function(ret) {
  53.            console.log('berhasil 2');
  54.            console.log(ret);
  55.        status=true;
  56.            
  57.         });
  58.     request2.fail(function(jqXHR, textStatus) {
  59.        console.log('error');
  60.        console.log(jqXHR,textStatus);
  61.     });
  62.  
  63.         console.log('sudah 2 detik');
  64.     }, 2000);
  65. //===================
  66.    
  67.    
  68.         return status;
  69. }
  70. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement