I am somehow stuck. Probably this is an easy question, but I just can’t get it working.
I am trying to access a response from an API (mapquest), but I can not find a way to dig into the reponse to extract the relevant information. Here is my console-log and my code, I actually want to access the responseJSON and some stuff in there (results).
JavaScript
x
24
24
1
var convertAddress = function(){
2
var PLZ = $("#PLZ").val();
3
var Ort = $("#Ort").val();
4
var Landkreis = $("#Landkreis").val();
5
var Umkreis = $("#Umkreis").val();
6
7
8
document.getElementById("lokalisierung").style.zIndex = "-1";
9
var url = 'http://open.mapquestapi.com/geocoding/v1/address?key=NEYE0LPf4hbAccEoG98DQbrRt5RB1700&location=Germany,' + PLZ ;
10
11
var D = $.ajax({
12
type: "GET",
13
url: url,
14
dataType: "json"
15
});
16
// console.log(PLZ);
17
// console.log(Ort);
18
// console.log(Landkreis);
19
// console.log(Umkreis);
20
console.log(D);
21
console.log(JSON.stringify(D));
22
console.log(Object.keys(D));
23
};
24
I found this stringify stuff on SO; but nothing worked as I expected, so probably there is a basic problem here.
Advertisement
Answer
You can access ur data with .done method. More information in official documentation jQuery Ajax
JavaScript
1
11
11
1
$.ajax( )
2
.done(function(data) {
3
// ur data
4
})
5
.fail(function() {
6
alert( "error" );
7
})
8
.always(function() {
9
alert( "complete" );
10
});
11
Done method is called when async call is done.