Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Rails CORS和jQuery自动完成_Javascript_Jquery_Ruby On Rails_Jquery Ui - Fatal编程技术网

Javascript Rails CORS和jQuery自动完成

Javascript Rails CORS和jQuery自动完成,javascript,jquery,ruby-on-rails,jquery-ui,Javascript,Jquery,Ruby On Rails,Jquery Ui,我有一个基于Rails的API。我试图通过jQueryUIAutoComplete获取数据并在select中显示它。但有一个错误: XMLHttpRequest cannot load http://api.exline.systems/regions/origin?title=%D0%95%D1%81. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://loc

我有一个基于Rails的API。我试图通过jQueryUIAutoComplete获取数据并在select中显示它。但有一个错误:

XMLHttpRequest cannot load http://api.exline.systems/regions/origin?title=%D0%95%D1%81. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 404.
我已经做了所有与标题的工作。例如,如果我通过浏览器发出直接请求:

我可以看到所有的头都由服务器提供:

Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Authorization
Access-Control-Allow-Methods:POST, PUT, DELETE, GET, OPTIONS
Access-Control-Allow-Origin:*
Access-Control-Request-Method:*
$(function() {
  $( '#calc-origin-ajax' ).autocomplete({
    source: function (request, response) {
      $.ajax(
      {
        url: 'http://api.exline.systems/regions/origin',
        dataType: "json",
        data: { title: request.term },
        success: function (data) { response(data); }
      });
    }
  });
});
但使用此代码,服务器不提供标头:

Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept, Authorization
Access-Control-Allow-Methods:POST, PUT, DELETE, GET, OPTIONS
Access-Control-Allow-Origin:*
Access-Control-Request-Method:*
$(function() {
  $( '#calc-origin-ajax' ).autocomplete({
    source: function (request, response) {
      $.ajax(
      {
        url: 'http://api.exline.systems/regions/origin',
        dataType: "json",
        data: { title: request.term },
        success: function (data) { response(data); }
      });
    }
  });
});

我应该怎么做才能让它工作?

为什么要提供指向的链接

但是试图向我提出请求


使用第一个链接时,一切正常:

不幸的是,在localhost下,它仍然不工作。没有这样的路线。也许我应该在浏览器中修复smth以允许本地主机请求?如果没有这样的路由,为什么要在代码中使用它?我很抱歉。。。就是好几个小时没睡了。即使你表现出错误,我也感到困惑