2017-02-16 2 views
-1

웹 서비스에서 일부 반환 값을 얻으려고하고 있는데 jQuery를 사용하고 있습니다.XHR로드 실패 : GET

나는 이러한 오류를 얻고있다 :

XMLHttpRequest를로드 할 수 없습니다 'HTTP를 ...'. 'Access-Control-Allow-Origin'헤더가 요청 된 리소스에 없습니다. 원본 'http://localhost:8181'은 (는) 액세스가 허용되지 않습니다.

XHR로드 실패 : 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

+2

다른 서버에서 AJAX 요청을 만드시겠습니까? 보안상의 이유로 직접 허용되지 않습니다. 가능한 해결책으로 [CORS] (https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS)를 조사 할 수 있지만 서버와 클라이언트는 프로토콜 지원 요청을 변경해야합니다 . – MrFlick

+0

예, 감사합니다. – Nagikho

+0

그것에 대해 많은 내용이 있습니다. 검색 바를 사용하십시오 –

답변

1

당신은 몇 가지를 사용하는 경우 당신은 당신의 요청 된 페이지에 다음 코드 ::

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

를 사용해야합니다 서버 측에서 PHP를 사용하는 경우 다른 아픔이 있다면 당신은 이와 비슷한 것을 발견해야합니다.

0

Allow-Origin 오류에 대한 web.config 파일에이 줄을 추가해야한다고 생각합니다.

<system.webServer> 
    <httpProtocol> 
    <customHeaders> 
     <add name="Access-Control-Allow-Origin" value="*" /> 
     <add name="Access-Control-Allow-Headers" value="Content-Type" /> 
     <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" /> 
    </customHeaders> 
    </httpProtocol> 
</system.webServer> 
+2

1) 메인 SO 사이트를 사용할 때 영어로 응답하십시오. 2) OP가이 솔루션을 사용할 수있는 모든 종류의 IIS 호스팅을 사용하고 있다는 징후가 없음 –

+0

하룬 영어로 답변을 작성해야합니다. –