Javascript Angular.js:URL验证始终返回200
我有一个网站(Angular.js为基础)和一个在线表单,用户可以输入任何URL。我想立即退出浏览器,检查输入的域是否有效(=可访问,可连接)。因此,我只需要标题信息(状态代码),而不是实际的网站内容。我尝试了这段代码,但无论地址是什么,它都会不断返回代码200:Javascript Angular.js:URL验证始终返回200,javascript,angularjs,http,Javascript,Angularjs,Http,我有一个网站(Angular.js为基础)和一个在线表单,用户可以输入任何URL。我想立即退出浏览器,检查输入的域是否有效(=可访问,可连接)。因此,我只需要标题信息(状态代码),而不是实际的网站内容。我尝试了这段代码,但无论地址是什么,它都会不断返回代码200: $scope.checkURL = function(index){ if($scope.items[index].address != ""){ $http({
$scope.checkURL = function(index){
if($scope.items[index].address != ""){
$http({
method: 'GET',
url: $scope.items[index].address
})
.success(function(data, status, headers, config){
if(status){
alert('yes!!'+status.toString()); //<--- always getting this!!!!
}
})
.error(function(data, status, headers, config){
if(status){
alert('error!!'+status.toString());
}
});
}
};
$scope.checkURL=函数(索引){
如果($scope.items[index].address!=“”){
$http({
方法:“GET”,
url:$scope.items[index]。地址
})
.success(函数(数据、状态、标题、配置){
如果(状态){
alert('yes!!'+status.toString());//我不确定……但是status
变量里面是什么?如果是200状态码,你必须用200来代替它。我知道。这就是我正在做的。问题是:为什么我总是得到代码200作为答案,即使是显然不存在的URL(google.comnetorg)??