Advertisement
GWibisono

random

Oct 7th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. <?php
  2. if(isset($_GET['reg'])){
  3.     $curl = curl_init();
  4.     $url=$_POST['url'];
  5.  
  6.         $parameter=isset($_POST['parameter'])?$_POST['parameter']:'';
  7.  
  8.         curl_setopt($curl, CURLOPT_URL, $url  );
  9.         curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  10.         if($parameter != '' && count($parameter)!=0 ) {
  11.             curl_setopt($curl, CURLOPT_POST, true);
  12.             curl_setopt($curl, CURLOPT_TIMEOUT, $maxTime);
  13.             curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($parameter,'','&'));
  14.             if( isset($_SERVER['HTTP_USER_AGENT']) ) curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  15.         }
  16.         else{
  17.  
  18.         }
  19.        
  20.         $response = curl_exec($curl);
  21.  
  22.         if (0 != curl_errno($curl)) {
  23.             $response = new stdclass();
  24.             $response->code = '500';
  25.             $response->message = curl_error($curl);
  26.         }
  27.         else{
  28.             $response0 = $response;
  29.             $response = json_decode($response,1);
  30.             if(!is_array($response)){
  31.                 $response=$response0;
  32.             }
  33.             else{
  34.                
  35.             }
  36.         }
  37.     echo is_array($response)?json_encode($response):$response;
  38.         curl_close($curl);
  39.     exit();
  40. }
  41. ?>
  42. <div id='xx'>
  43.  
  44. </div>
  45.  
  46.  
  47. <script type="text/javascript" charset="utf8" src="jquery-1.11.3.js"></script>
  48. <script>
  49.  
  50. function call_kota(urlTarget){
  51.     var request = jQuery.ajax({
  52.           url: "?reg=1",
  53.           type: "post",
  54.           dataType: "json",
  55.           data:{url:urlTarget}
  56.     });
  57.     request.success(function(respon) {
  58.         console.log('data terpanggil');
  59.         console.log(respon);
  60.     });
  61.     request.error(function(errors,msg){
  62.         console.log(msg);
  63.         console.log(errors);
  64.     });
  65. }
  66.  
  67. call_kota("http://priangan.org/api/city");
  68. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement