JSONP example

http://stackoverflow.com/questions/27255347/how-can-i-get-a-value-from-another-webpage-and-store-it-as-a-variable

by Financial Modeling Prep

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-csv/0.71/jquery.csv-0.71.min.js"></script>
<pre id='data'></pre>

JavaScript

// data format [{"target": "snmp.ssbSubstation.realEnergy.1", "datapoints": [[4511552439.0, 1417540920]]}]

// http://www.mocky.io/v2/547df7d558eb49190856a759

(function ($) {
    var url = 'https://financialmodelingprep.com/api/v3/search?query=NBR&apikey=demo'; // mocky.io demo source

    var jsonCallback = function (data) {
    conso.log(data);
        var gauge = data[0].datapoints[0][0];
        console.log(gauge);
        
        $('#data').html(JSON.stringify(data, null, 2));
        $("</p>").text('value for gauge ' + gauge).appendTo('#data');
    };

    $.ajax({
        type: 'GET',
        url: url,
        contentType: "application/json",
        dataType: 'jsonp'
    }).done(jsonCallback)
    .fail(function (xhr) {
        alert("error" + xhr.responseText);
    });

})(jQuery);