Stay Connected

Follow ERS on Twitter
Subscribe to RSS feeds
Subscribe to ERS e-Newsletters.aspx
Listen to ERS podcasts
Read ERS blogs at USDA

jQuery Code Snippet

[source available at]

Sample jQuery Code

The following example is for a JSON-formatted response written with jQuery v1.9.1. Note:  ERS APIs require a key which can be obtained at

    <title>USDA ERS API web service call using jSON</title>
        <script src="" type="text/javascript"></script>
        <script type="text/javascript">
          /* CODE SAMPLE: retrieve list of ARMS reports using ERS API */**_
          function GetARMS() {      
   = true;
            var jsonp_url = "";
              url: jsonp_url,                   
              type: 'GET',          
              dataType: 'jsonp',
              jsonpCallback: 'jsonCallback',               
              crossDomain: true,  
              success: function() { console.log("success"); },
              error: function() { console.log("error"); }                 
          function jsonCallback(data) {
               //alert('in jsonCallback');
            var reports = data.dataTable; // this array has the data
            var strResult = "<table><th>Report Number</th><th>Report Description</th>";
            $.each(reports, function (index, Report) {
              strResult += "<tr><td>" + Report.report_num + "</td><td> " + Report.report_header + "</td></tr>";
            strResult += "</table>"; 
        <h3>USDA ERS API demo </h3>
        <button onClick="GetARMS();return false;">ARMS Surveys</button></p>
        <div id="divResultARMS"></div>

Last updated: Monday, December 23, 2013

For more information contact: Website Administrator