无访问控制源

时间:2015-07-13 10:40:49

标签: jquery

我收到以下错误No' Access-Control-Allow-Origin'标头出现在请求的资源上。起源' http://localhost:8080'因此,当我执行以下代码时,不允许访问 我无法访问http://localhost:8983中的代码但可以修改8080端口服务器代码。 以下是我的代码

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>

  <script>
  $(function() {


    $( "#name" ).autocomplete({
      source: function(request,response){
             var name = $("#name").val();

          $.ajax({
              type:"GET",
        //    contentType: "application/json; charset=utf-8",
              url: "http://localhost:8983/solr/test/suggest",
              data: "suggest=true&suggest.build=true&suggest.dictionary=mySuggester&wt=json&suggest.q="+name,
        //      url: "./search.html",
        //   data: "name=" + name,
              success: function (data) {
                  if (data != null) {

                      alert(data);
                  }
              },
              error: function(result) {
                  alert("Error");
              }
          })
      }
    });

    $("#search").click(function () {

         var name = $("#name").val();

         $.ajax({
            type: "GET",
             url: "./search.html",
             data: "name=" + name,
             success: function(response){
                    // we have the response
                    $('#results').html(response);
                     },
                     error: function(e){
                     alert('Error: ' + e);
                 }

         });

     });







  });
  </script>
</head>
<body>

<div class="ui-widget">
  <label for="tags"> </label>
  <input id="name">
  <input type="button" name="search" id="search" value="submit" />

</div>
    <div id="results"></div>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

我想您想了解CORS的工作原理:https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

您需要对服务器端进行一些修改以允许您的请求。