When querying geocoding with state/country, I sometimes encounter issues where the JSON responses are not parsed properly. How can I handle these errors and continue to the next response?
Below is the AJAX call:
$.ajax({
url: "/abc/points",
context: document.body,
data: {
latitude: places[0].geometry.location
.lat(),
longitude: places[0].geometry.location
.lng(),
distance: $(
'input[name="distance"]:checked')
.val(),
city: city1,
state: state1,
country: country1,
},
success: function(responseText) {
$("#response-div").html(
responseText);
$("#response-div")
.find("script")
.each(
function(i) {
eval($(
this)
.text());
});
$("html").removeClass(
"wait");
}
});
There may be numerous results returned, and I simply want to skip over those that cause syntax errors and proceed with the next one. If needed, I can provide a sample of the JSON text returned.
Thank you
COMMENT I am unsure if it's possible to ignore syntax errors, so I'm exploring an alternative approach. Essentially, I need to replace both '\n' characters and commas in a JSON response being parsed into JSTL. Any guidance on how to achieve this would be greatly appreciated. While there are solutions for ignoring one or the other, combining both replacements seems to be a challenge.
function(marker, event, context) {
var contentString = '<div style="width:600px; height: 300px;">' +
'<div> <h4>' + '${fn:replace(object.name, search, replace)}' + ' </h4> </div>' +
'<table class="table">' +
'<tbody>' +
'<tr class="active">' +
'<td>Address: </td>' +
<c:set var="address" value="${object.stAddress} ${object.city}, ${object.state} ${object.zipcode}" />
'<td colspan=5>' + "${fn:replace(address, ",", " ")}"+"${fn:replace(address, "\n", " ")}" + '</td>' +
' </tr>' +
Edit I have attempted various methods to replace special characters but have encountered challenges specifically with '\n'
<c:set var="search" value="'" />
<c:set var="replace" value="" />
<c:set var="newLn" value="\n" />
${fn:replace(fn:replace(address, newLn, replace), search, replace)}