How to Query JSON Data in Ajax Request
I have a json file as:
- {"markers":[
{ "latitude":11.58655, "longitude":122.755402, "type":"A"},
{ "latitude":11.00698, "longitude":124.612801, "type":"B"},
{ "latitude":10.30723, "longitude":123.898399, "type":"A"},
{ "latitude":11.24775, "longitude":125.003502, "type":"C"},
{ "latitude":11.03693, "longitude":125.719498, "type":"Z"}
]}
and an ajax request as:
- $.ajax({
type: "POST",
url: 'data.txt',
dataType: 'json',
success: function(data){ locations.length = 0;
for (p = 0; p < data.markers.length; p++) {
locations.push(Array(data.markers[p].latitude,data.markers[p].longitude));
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data.markers[p].latitude,data.markers[p].longitude),
map: map, title:"marker "+p }); } },
error: function (xhr,status,errorStr) {
alert("status="+status+", error="+errorStr);
}
});
which is working fine for me but I need to get the data based on their TYPE.Can you please let me know if there is a way I can request based on a type like "A" so I get ONLY data that have a TYPE = A