测试服务器的响应

时间:2014-04-14 10:22:41

标签: javascript angularjs http get

我的角度应用中有一个表单,用户需要提供有效的网址。 因此,在提交表单时,我想通过向提供的URL发出get请求来测试URL是否有效,并检查服务器是否发送200。

单击提交按钮时,将运行以下代码:

$http.get(scope.target_url).success(function(){
                // some code 
            }).error(function(error){
                console.log(error);
            });

然而,我从未得到过成功的回答: - 如果我提供的网址如下:'http://www.somesite.com',我会:

XMLHttpRequest cannot load 'http://www.somesite.com'. Received an invalid response. Origin 'mydomain' is therefore not allowed access.
  • 如果我提供的网址如下:'http://somesite.com',我会:

    XMLHttpRequest无法加载http://somesite.com/。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许原点'mydomain'访问。

问题出在哪里?

1 个答案:

答案 0 :(得分:1)

这是正常的安全限制。在这里阅读CORS:

http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

相关问题