/ Published in: PHP
A PHP proxy for jQuery AJAX cross-domain requisitions, created to support friendly-url API\\\\'s.
Expand |
Embed | Plain Text
<?php $base_url = 'http://www.yoursite.com/api/'; $chamada = $chamada[2]; // if this php file is in a subdirectory you may change this key $url = $base_url.$chamada; $ch = curl_init(); if ($method == 'get') { if ($_SERVER['QUERY_STRING']) $url .= '?' . $_SERVER['QUERY_STRING']; curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_URL, $url); } else { curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST); curl_setopt($ch, CURLOPT_URL, $url); } $data = curl_exec($ch); curl_close($ch); ?> <!-- Example --> $.get('proxy.php/my_api_call'); $.post('proxy.php/my_post_api', {id:user_id});
You need to login to post a comment.
