My goal is to extract the asciiName from a specific URL:
http://services.gisgraphy.com/geoloc/search?lat=21.283300399780273&lng=72.9832992553711&radius=10000<br>
I am utilizing ajax jsonp for this task.
Below is the complete code snippet:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<Script>
var asciilast;
var asciiname="";
var lat="21.283300399780273";
var lng="72.9832992553711";
var radius="10000";
function getascii(){
$.ajax({
url: "http://services.gisgraphy.com/geoloc/search?lat="+lat+"&lng="+lng+"&radius="+radius+"&format=json",
async: false,
dataType:'jsonp',
success: function(data1) {
for(i=0;i<data1.result.length;i++) {
asciiname = asciiname+data1.result[i].asciiName+",";
console.log(asciiname);
asciilast = asciiname.replace(/\,$/, '');
}
alert(asciilast);
}
});
}
</Script>
<body onload="getascii()">
</body>
This code has been effective in providing the desired output.
However, there are instances when it encounters issues such as returning undefined if certain results do not have an asciiName.
To address this issue, I want to avoid obtaining undefined values when the result lacks an asciiName.