Home » Jquery » javascript – content_scripts. Why this code works in Chrome and does not work in Firefox?-Exceptionshub

javascript – content_scripts. Why this code works in Chrome and does not work in Firefox?-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

The code adds an IMDB rating for movies to the page.

var jqxhr = $.getJSON('https://omdbapi.com/?t='+encodeURI(name)+'&y='+year+'&apikey=fde63f02')
        .success(function() { console.log("Successful execution"); })
        .error(function() { console.log("Runtime error"+name+'&y='+year); })
        .complete(function() { console.log("Completion of execution"); });

        $.getJSON('https://omdbapi.com/?t='+name+'&y='+year+'&apikey=fde63f02',
        function(data){
            console.log(data);
            var imgurl = chrome.extension.getURL("images/Button.png");
            if (Number(data.imdbRating)<6) {
                imgurl = chrome.extension.getURL("images/Button1.png");
            }
            else if (Number(data.imdbRating)>=8) {
                imgurl = chrome.extension.getURL("images/ButtonTop.png");
            }           
            var btn = '<a target="_blank" class="IMDBanchor" href="http://www.imdb.com/title/'+data.imdbID+'"><span class="Rating" style="background: no-repeat url('+imgurl+')">IMDB '+data.imdbRating+'<span></a>';
            console.log(data);
            $(v).parent().append(btn)
            }
            );

A button “btn” appears in Chrome.
Firefox displays an error in the console.
Update:
Added: .error(function(err) { console.log(err); })
I get “err” in the console

{…}
abort: function abort(statusText)​
always: function always()​
complete: function done()​
done: function done()​
error: function done()​
fail: function done()​
getAllResponseHeaders: function getAllResponseHeaders()​
getResponseHeader: function getResponseHeader(key)​
isRejected: function isResolved()​
isResolved: function isResolved()​
overrideMimeType: function overrideMimeType(type)​
pipe: function pipe(fnDone, fnFail)​
promise: function promise(obj)
readyState: 0
responseText: ""
setRequestHeader: function setRequestHeader(name, value)
status: 0
statusCode: function statusCode(map)
statusText: "error"
success: function done()​
then: function then(doneCallbacks, failCallbacks)​
<prototype>: Object { … }

I do not understand what it means.

How to&Answer: