-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathajax.js
30 lines (26 loc) · 873 Bytes
/
ajax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* AJAX Example - Making Requests to the SimplyRETS API
*/
// These are your API Credentials - base64 encode them in the
// `Authorization` header.
var auth = btoa("simplyrets:simplyrets");
function main() {
$.ajax({
// make an AJAX request - this is the /properties endpoint
url: "https://api.simplyrets.com/properties",
type: 'GET',
dataType: 'json',
// authorize with the API credentials
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic " + auth);
},
success: function(res) {
// res is the set of listings returned from the API
// loop through them and print the address
for(var i=0; i < res.length; i++) {
$("#app").append("<p>" + res[i].address.full + "</p>");
}
}
});
}
main();