Can Not Get Data From Ajax Request To The Coinhive Api
I recently tried to get the data from a Json API and post that back to a table in html. I tried to do this from: https://api.coinhive.com/user/balance?name=username&secret=myse
Solution 1:
figured it out!
The JSON request:
<?php$url = 'the api url';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/x-www-form-urlencoded"
));
$data = curl_exec($ch);
curl_close($ch);
$result = json_decode($data, true);
?>
The postback to the end user:
<spanid="test"style="color:white"><?phpif (isset($data))
{
echo$result['balance'];
}
else
{
echo'damn';
}
?></span>
I decided to go with php and kind of ditch the html getjson part.
Solution 2:
Client side requests to the Coinhive HTTP API are restricted by CORS rules:
You should never call the Coinhive HTTP API from the client side.
Post a Comment for "Can Not Get Data From Ajax Request To The Coinhive Api"