Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
51 lines (40 sloc) 1.88 KB

jQuery Example

The purpose of this document is to provide example code for interacting with ARMS data via its REST API.

    <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>
        <p><button onClick="GetARMS();return false;">ARMS Surveys</button></p>
        <div id="divResultARMS"></div>