Hello and thank you for the time you are taking to look at this.
The problem I am having is with a JSON return from a third party service so I have no control over how the JSON is formatted. I am using the following (stripped down to the important pieces)
function JSONgrabber(Zip,iplocation)
{
var requestBase ="http://www.someCompany.com/api/request";
var requestData ="iplocate=true&output=json&callback=useJSON";
var request=requestBase+"&&zip="+Zip+"&"+requestData;
if(iplocation ==false || iplocation=="false")
{
request=request.replace("iplocate=true","iplocate=false");
}
if (document.getElementById("JSONDataMaster"))
{
var element = document.getElementById("JSONDataMaster");
element.parentNode.removeChild(element);
}
try{
var head = document.getElementsByTagName("head").item(0);
var script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.setAttribute("src", request);
script.setAttribute("id", "JSONDataMaster");
head.appendChild(script);
}
catch(err){console.log("Problem loading JSON Data");}
}
function useJSON(JSONDATA){}
This works 99% of the time just as expected but on occasion the return has something like
Joe's Diner and the ' causes a Uncaught SyntaxError: Unexpected identifier, this happens during the return so I have not been able to work with it via replace etc to fix it as it never gets to the callback function.
any insight is much appreciated. I am not using any outside libraries (jquery etc) so please any help needs to be pure JS (perhaps php)