/    Sign up×
Community /Pin to ProfileBookmark

javascript is working in google chrome but not in IE or firefox

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 !!!”);
}
“`

to post a comment
JavaScript

0Be the first to comment 😎

×

Success!

Help @charanguddu spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...