Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if(isset($_GET['reg'])){
- $curl = curl_init();
- $url=$_POST['url'];
- $parameter=isset($_POST['parameter'])?$_POST['parameter']:'';
- curl_setopt($curl, CURLOPT_URL, $url );
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- if($parameter != '' && count($parameter)!=0 ) {
- curl_setopt($curl, CURLOPT_POST, true);
- curl_setopt($curl, CURLOPT_TIMEOUT, $maxTime);
- curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($parameter,'','&'));
- if( isset($_SERVER['HTTP_USER_AGENT']) ) curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
- }
- else{
- }
- $response = curl_exec($curl);
- if (0 != curl_errno($curl)) {
- $response = new stdclass();
- $response->code = '500';
- $response->message = curl_error($curl);
- }
- else{
- $response0 = $response;
- $response = json_decode($response,1);
- if(!is_array($response)){
- $response=$response0;
- }
- else{
- }
- }
- echo is_array($response)?json_encode($response):$response;
- curl_close($curl);
- exit();
- }
- ?>
- <div id='xx'>
- </div>
- <script type="text/javascript" charset="utf8" src="jquery-1.11.3.js"></script>
- <script>
- function call_kota(urlTarget){
- var request = jQuery.ajax({
- url: "?reg=1",
- type: "post",
- dataType: "json",
- data:{url:urlTarget}
- });
- request.success(function(respon) {
- console.log('data terpanggil');
- console.log(respon);
- });
- request.error(function(errors,msg){
- console.log(msg);
- console.log(errors);
- });
- }
- call_kota("http://priangan.org/api/city");
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement