Skip to content

Instantly share code, notes, and snippets.

@slick2
Last active August 3, 2017 13:20
Show Gist options
  • Save slick2/a16d81dd3693a70fefa92742d12a8d33 to your computer and use it in GitHub Desktop.
Save slick2/a16d81dd3693a70fefa92742d12a8d33 to your computer and use it in GitHub Desktop.
sample ajax method
class Users{
public function xhr_contactList(){
//make a curl call
$url = https://www.namesilo.com/api/contactList?version=1&type=json&key=12345
//response
$result = $this->_http_get($url);
$return = json_decode($result);
echo $return;
}
private function _http_get($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array());
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment