title: How to use Javascript to pull api, run calculations on pull data, and post results to webpage?
body: <p>I am attempting to inject code into a webpage. Here is the situation: </p>
  
  <p>api url: <a href="https://blockchain.info/q/hashrate" rel="nofollow noreferrer">https://blockchain.info/q/hashrate</a></p>
  
  <p>calculation: ((hashrate * 1249)/(27518 * 1000000)</p>
  
  <p>then post calculation result to page. </p>
  
  <p>Here is the javascript I have created so far: </p>
  
  <pre><code>$(document).ready(function () {
      $.ajax({
          url: 'https://blockchain.info/q/hashrate',
          type: "GET",
          dataType: "jsonp",
          success: function (data) {
              console.log(data);
              var hashrate = (data);
              var miner_cost = ((hashrate * 1249)/(27518 * 1000000)
              $.html(miner_cost);
          }
      });
  });
  </code></pre>
  
  <p>I have already created this successfully in python: </p>
  
  <pre><code>import requests
  import json
  
  url = 'https://blockchain.info/q/hashrate'
  
  BTC_Hashrate = requests.get(url).json()
  
  BTC_Minercost_S15_28T = ((BTC_Hashrate *1249)/(28*39*2016*12.5*1000))
  
  print BTC_Minercost_S15_28T
  </code></pre>
  
  <p>Any help would be greatly appreciated. Forgive me Javascript gods for I have sinned... I am a python user. </p>
  
  <p>Many Thanks!</p>