请问怎么连服务器?

我的服务在localhost:3000,现在点击预留启动的是localhost:7456。在项目里面将url设置为:let url = “localhost:3000/login”;会返回错误

Login.js:33 XMLHttpRequest cannot load localhost:3000/login. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

以下是我的代码:

    doReq:function(){
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
                var response = xhr.responseText;
                console.log(response);
            }
        };
        let url = "login";
        xhr.open("GET", url, true);
        xhr.send();
    },

应该是跨域的问题,我将3000的服务器和chrome都添加了跨域的,但还是没用。是7456服务器的问题吗?如果是,要怎么修改???

附上我尝试过的方法
1: 如何解决跨域问题:==无效==里面主要是说使用cors插件。
2: 修改chrome启动项==无效==

你localhost:3000的服务设置一个header:
Access-Control-Allow-Origin: *

非常感谢。可以了

我之前也这样干的,但是无效,现在有有效了。不知道为什么。。。

添加了如下的代码在3000服务器上。

//allow custom header and CORS
app.all('*',function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
  res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');

  if (req.method == 'OPTIONS') {
    res.send(200); /让options请求快速返回/
  }
  else {
    next();
  }
});