weixin_33675507 2017-02-16 14:54 采纳率: 0%
浏览 302

XHR加载失败:GET [重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/20035101/why-doesn-t-postman-get-a-no-access-control-allow-origin-header-is-present-on" dir="ltr">Why doesn’t Postman get a “No 'Access-Control-Allow-Origin' header is present on the requested resource” error when my JavaScript code does?</a>
                            <span class="question-originals-answer-count">
                                (8 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2017-02-16 14:59:43Z" class="relativetime">3 years ago</span>.</div>
        </div>
    </aside>

I am trying to get some return value from Web Service and i am using ajax jQuery.

I am getting these errors:

XMLHttpRequest cannot load 'http....'. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8181' is therefore not allowed access

XHR failed loading: GET "http...".

<script language="text/javascript">
  getUserValue();

  function getUserValue() {
    var number = "0000317930";
    var fullName = "NURULLAH ALTINTAŞ";
    var dataString = "{ 'number' : '" + number + "', 'fullName' : '" + fullName + "'}";
    $.ajax({
      type: "GET",
      url: "http://...",
      data: {
        number: number,
        fullName: fullName
      },
      contentType: "application/x-www-form-urlencoded; charset=UTF-8",
      dataType: "xml",
      success: OnSuccessGetConnectionArticles,
      failure: OnFailureGetConnectionArticles,
      error: OnErrorGetConnectionArticles
    });
  }

  function OnSuccessGetConnectionArticles(response) {
    debugger;
    $.each(response.RestResponse.result, function(index, value) {
      $("#list").append('<li><span class="tab">' + value.name + '</span></li>');
    });
  }

  function OnErrorGetConnectionArticles(response) {
    debugger;
    alert(response.d);
  }

  function OnFailureGetConnectionArticles(response) {
    debugger;
    alert(response.d);
  }
</script>

enter image description here

</div>
  • 写回答

2条回答 默认 最新

  • weixin_33726318 2017-02-16 14:59
    关注

    If you are using PHP in server side you should use in your requested page the following code::

    $origin = 'http://localhost:8181';
    header("Access-Control-Allow-Origin: " . $origin);
    

    if you are using some other anguage then you should find similar to this.

    评论

报告相同问题?

悬赏问题

  • ¥15 Macbookpro 连接热点正常上网,连接不了Wi-Fi。
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析