NS_ERROR_DOM_BAD_URI: Access to restricted URI denied

If our js file contains Ajax code, and references the HTML file of this js file, open the test directly locally, this error will appear:
as shown below:
util. Js file

function ajax(url,options,type){
    var oAjax=null;
    var type=type || "GET";
    //alert(type);
    if(window.XMLHttpRequest){
        oAjax=new XMLHttpRequest();

    }
    else{
        oAjax=new ActiveXObject('Microsoft.XMLHTTP');
    }

    oAjax.onreadystatechange=function(){
        if (oAjax.readyState==4) {
            if (oAjax.status==200) {
                options.onsuccess(oAjax.responseText);
            } 
            else{
                options.onfail();
            };
        };
    }

    url=url+"?name="+options.data.name+"&password="+options.data.password+"&t="+Math.random();
    oAjax.open(type,url,true);
    oAjax.send();
}

Assuming that there are other functions in the util.js file that we need, when we introduce util.js into the HTML file, the local browser opens the test with an error

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>task0002</title>
    <script type='text/javascript' src='js/util.js'></script>
</head>
<body>
   <textarea name="hobby" id="hobby" cols="30" rows="10"></textarea><br/>
    <input type="button" id='btn' value='filtration'>
    <script>
        var oTxt=document.getElementById('hobby');
        var btn=document.getElementById('btn');
         var p=document.createElement('p');
         document.body.appendChild(p);
        btn.onclick=function(){
            var hobbys=oTxt.value;
            var ary=hobbys.split(/[,、;\n\s,\u3000]/);
            ary=uniqArray(ary);
            p.innerHTML="";
            p.innerHTML="hobby:"+ary.join("<br/>");
        }
    </script>
</body>
</html>

The reason: When local browsing opens the page, a cross-domain problem occurs, so the message is that you don’t have permission
Solution:
1. Put the ajax code part in the HTML file, there will be no problem
2. By placing the project folders on the server, they will be in one domain by default and cross-domain problems will not occur

Read More: