2014-11-25 2 views
0

는 다음과 같은 코드를 생각해 보자. 하지만 아약스 호출을 통해 그것을 할 때,이 오류가 발생합니다 :JQuery와 인증 오류

Failed to load resource: the server responded with a status of 401 (Unauthorized) 
jquery.min.js:5 XMLHttpRequest cannot load  http://10.91.240.21:9898/jolokia/read/* No  'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 401. 
(index):1 Uncaught SyntaxError: Unexpected token u 

TRY 2 :

 var jsonData2 = $.ajax({ 
     type:'GET', 
     url: 'http://'+domainName+':9898/jolokia/read/*', 
     dataType:"jsonp", 
     crossDomain: true, 
     data: {username: '*',password: '*'}, 
     async: false 
     }).responseText; 

    var parsed2 = JSON.parse(jsonData2); 

내가 JSON p를 사용하여 시도합니다. 승인되지 않은 코드가 해결되었습니다. 상태를 OK로 표시하고 있습니다. 하지만 이제이 오류가 발생합니다.

Uncaught SyntaxError: Unexpected token u 
+0

http://stackoverflow.com/questions/5507234/how-to-use-basic-auth-and-jquery-and-ajax – Cheery

+0

@Cheery 나는 beforeSend 인수를 사용하고 있습니다. –

+0

링크로 두 번째 대답을보십시오. 현대적인 jQuery에는 사용자 이름과 비밀번호 속성이 있습니다. 또는, 적어도, 속성 헤더 – Cheery

답변

1

나는 대답을 얻었습니다. 도메인 간 문제가 해결되었습니다.

 $(document).ready(function() { 
     var surl = "http://www.anotherdomain.com/webservice.asmx"; 
     $.ajax({ 
      type: 'GET', 
      url: surl, 
      crossDomain: true, 
      contentType: "application/json; charset=utf-8", 
      data: { UserID: 1234 }, 
      dataType: "jsonp", 
      async: false, 
      cache: false 
     }); 
     });