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:
- Android installation failed due to invalid URI
- java.lang.IllegalArgumentException : URI is not absolute error
- java.lang.IllegalArgumentException : URI scheme is not “file” error resolution
- Solve the unmarshalling error: unexpected element (URI: “local:” name “). Expected elements are
- WeChat official account web page authorized, redirect_ Uri parameter error, solution!
- ER_ACCESS_DENIED_ERROR: Access denied for user ‘root‘@‘localhost‘ (using password: NO)
- Docker Nacos deployment uses container name to access 400 bad request
- JS error: permission denied to access property ‘document’— document.domain -The same source strategy of JavaScript
- 【docker】 denied: requested access to the resource is denied
- Error: permission denied to access property “ref”
- HTTP Error 401.1 – Unauthorized:Access is denied due to invalid credentials
- Error 1045 (28000): solution to access denied for user ‘root’ @’localhost ‘(using password: no)
- MySQL Access denied
- ERROR 1044 (42000): Access denied for user ”@’localhost’ to database ‘mysql’
- HTTP Basic: Access denied
- Fabric appears when trying to use application call: Unknown: access denied: Channel [mychannel] creator org [org1msp]
- Springboot uses druid to log in MySQL. An error occurred: access denied: errorcode 1045, state 28000
- Could not install packages due to anenvironment error: [winerror 5] access denied
- git remote: HTTP Basic: Access denied error resolution
- Error: could not install packages due to an environmenterror: [winerror 5] access denied.