-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.js
More file actions
42 lines (37 loc) · 948 Bytes
/
main.js
File metadata and controls
42 lines (37 loc) · 948 Bytes
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
31
32
33
34
35
36
37
38
39
40
41
42
$(function(){
function onAjaxSuccess(data) {
if(data.result == 200) {
$("#result_content")
.hide("slow", function() {
$("#result_content")
.empty()
.append("<p>" +
"<label>Logradouro: </label>" + data.data['logradouro'] +
"<br />" +
"<label>Bairro: </label>" + data.data.bairro +
"<br />" +
"<label>Cidade: </label>" + data.data.cidade +
"<br />" +
"<label>Estado: </label>" + data.data.estado +
"</p>")
.show("slow");
});
} else {
onAjaxError(data);
}
}
function onAjaxError(data) {
$("#result_content")
.empty()
.append(JSON.stringify(data))
.show("slow");
}
function onSubmitClick() {
$("#result_content").hide("slow");
$.getJSON("https://api.postmon.com.br/v1/cep/" + $("#cep").val()).
success(onAjaxSuccess).
error(onAjaxError);
};
$("#result_content").hide();
$("#submit").click(onSubmitClick);
});