cors
Header set Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, content-type"
Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
basic auth is also set
AllowOverride AuthConfig
further settings on the server side
cd / var/www/html & & vim .htaccess
AuthName "login"
AuthType Basic
AuthUserFile / var/www/html/passwd
require user username
Create password for username.
htpasswd-c / var/www/html/passwd username
systemctl restart httpd
enter 111.111.111.111 to jump out of the authentication window, enter the account number, password, passed, and now you can start testing the jquery code.
function Ajax( ) {
var username="xxxx";
var password="xxxx";
var url = "http://111.111.111.111/remote.html";
$.ajax(url, {
type:"GET",
dataType: "html",
crossDomain: true,
headers: {
"Authorization": "Basic " + btoa(username + ":" + password)
},
success:function(response){
mytext = $("remote");
mytext.append(response);
},
error: function (e) {
alert("error");
}
});
};
the above code cannot be verified. Excuse me, why?