Connect To An API Using JQUERY

Connect To An API Using JQUERY

Connect To An API Using JQUERY

The Below Code Snippet , shows how to connect to An API Using jQuery

In this Example Code , i will Connect to  Data.gov.sg to draw average House Hold Income Data  Segregated by Type of Property dwelling

 

</pre>
$(function(){

// Data Acquisition--------------------------------------------------
$.ajax({
url: "https://data.gov.sg/api/action/datastore_search?resource_id=c8348b33-9f6d-471e-8652-a69286af3f79&limit=200",

//dataType: "json",
success: callback,
error: function(err) {
alert("Oops there was an error");
}
});


function callback(response) {

// alert Connected

alert("Connected");

// Log Data in Console

console.log(response);

// After Connected , write what you want to do here

//Alert Value reside in records array 0 and Reside in result

alert(response.result.records[0].value);


}

});
<pre>

Results

 

Console Result
Console Result

 

Leave a Reply

Your email address will not be published. Required fields are marked *

13 − 11 =