gpt4 book ai didi

javascript - 测试服务器的响应

转载 作者:可可西里 更新时间:2023-11-01 16:37:58 25 4
gpt4 key购买 nike

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

当点击提交按钮时,运行以下代码:

$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” header 。因此不允许访问源“mydomain”。

问题从何而来?

最佳答案

这是正常的安全约束。在此处阅读有关 CORS 的信息:

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

关于javascript - 测试服务器的响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23057664/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com