I have a Javascript and HTML code which is perfectly working with Google Chrome but not working in IE or Firefox. Basically what it does is, it just fetches the data from a server file and loads it in the browser.
In Firefox, when I click on the link I am getting the below error message
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
“`
function serverData(command, param){
console.log(“command is “+command+ ” param is “+param);
if(!command){
console.log(“Command not recieved, No call to Server”);
return;
}
var url = “test.cgi?command=”+command;
if(param)
url += “&”+param;
var headers = new Headers();
headers.set(‘Accept’, ‘application/json’);
var fetchOptions = {
method: ‘GET’ ,
headers
};
console.log(“url is “+url);
fetch(url, fetchOptions)
.then(
function (response){
if(response.status !== 200){
console.log(“There is some problem for request: “+command+” status: “+response.status);
return;
}
response.json().then( function(data){
responseHandler(command, data);
});
}
)
.catch(function (error){
console.log(“Exception: “+error);
});
}
function responseHandler(command, jsonData){
if(!jsonData){
console.log(“Json from server not defined!!!”);
return;
}
switch(command){
case “set”:
if(jsonData.result == “success”){
console.log(“Policy committed successfully!”);
document.getElementById(‘info’).innerHTML = “INFO: Policy committed successfully!”;
document.getElementById(“info”).style.color = ‘green’;
}
else{
if(jsonData.options && jsonData.options.length > 0){
var failedOptions = “”;
for (var i=0; i < jsonData.options.length; i++){
failedOptions+=” “+jsonData.options[i];
}
console.log(“Failed to commit following option(s):”+failedOptions);
document.getElementById(‘info’).innerHTML = “ERROR: Failed to commit following option(s)-“+failedOptions;
}
else{
console.log(“Failed to Commit”);
document.getElementById(‘info’).innerHTML =”ERROR: Failed to Commit”;
}
initialPageLoad();
document.getElementById(“info”).style.color = ‘red’;
}
break;
case “get”:
if(jsonData.MINLEN_RANGE){
console.log(“jsonData.MINLEN_RANGE is “+jsonData.MINLEN_RANGE);
document.getElementById(“Minlen_range”).value=jsonData.MINLEN_RANGE;
document.getElementById(“Minlen_text”).value=jsonData.MINLEN_RANGE;
}
break;
default:
console.log(“we don’t support this”);
}
}
function initialPageLoad(){
console.log(“Retrieving data from Server calling get”);
serverData(“get”);
console.log(“Password Policy data loaded !!!”);
}