Я использую jQuery, чтобы проверить, доступен ли сервер с другого сервера.
Код, который я использую для этого:
urlExists(newUrl, function(exists) {
console.log (exists)
});
function urlExists(url, callback){
$.ajax({
type: 'HEAD',
url: url,
success: function(){
callback(true);
},
error: function() {
callback(false);
}
});
}
Это всегда приводит к:
HEAD http://192.168.0.209/test/ 401 (Unauthorized)
cors.php:1 Failed to load http://192.168.0.209/test/: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.0.20' is therefore not allowed access. The response had HTTP status code 401.
Я попытался добавить значения заголовка CORS в мой .htaccess
и мой .conf
для этого сайта, и я бегу a2enmod headers
кажется, ничего не помогает.
Header set Access-Control-Allow-Origin "*"
Файл .conf:
Alias /test /www/test/
<Directory "/www/test/">
DirectoryIndex index.php
AllowOverride All
Options +ExecCGI
Require all granted
</Directory>
.Htaccess в / www / test:
AuthUserFile /home/userA/.htpasswd
AuthName EnterPassword
AuthType Basic
<Limit GET POST>
require valid-user
</Limit>
Может кто-нибудь посоветовать, как заставить это работать? Я прочитал множество примеров здесь, но ни один не помог.
Спасибо
Задача ещё не решена.
Других решений пока нет …