서버에서 인증 한 후 액세스 할 수있는 일련의 REST URI가 있습니다. 이 서비스는 로그인 정보가있는 JSON 입력을 가져 와서 세션 ID가있는 JSON 출력을 검색합니다.rest webservice를 호출 할 때 Jquery ajax가 실패 함
크롬 확장 프로그램과 같이 나머지 클라이언트를 사용할 때는 모든 것이 작동합니다.
이제는 JS를 사용하여 구현하려고하지만 실패 반환에도 불구하고 무엇이 잘못되었는지 (오류 메시지가 비어 있음) 세부 정보를 볼 수없고 코드에서 누락 된 부분을 찾을 수 없습니다.
$.ajax({
// the URL for the request
url: "https://host002:50000/b1s/v1/Login",
// the data to send (will be converted to a query string)
data: {
UserName: "manager",
Password: "1234",
CompanyDB: "CUS_001"
},
// whether this is a POST or GET request
type: "POST",
// the type of data we expect back
dataType : "json",
// code to run if the request succeeds;
// the response is passed to the function
success: function(json) {
$("<h1/>").text(json.title).appendTo("body");
$("<div class=\"content\"/>").html(json.html).appendTo("body");
},
// code to run if the request fails; the raw request and
// status codes are passed to the function
error: function(xhr, status, errorThrown) {
alert("Sorry, there was a problem! " + xhr.responseText);
console.log("Error: " + errorThrown);
console.log("Status: " + status);
console.dir(xhr);
},
// code to run regardless of success or failure
complete: function(xhr, status) {
alert("The request is complete!");
}
});
xhr.response 텍스트는 항상 비어 있습니다. 상태는 항상 오류입니다. errorThrown은 항상 비어 있습니다.
나는 또한 $ post 메서드를 사용해 보았지만 같은 동작을 보였다.
크로스 오리진 제한이 될 수 있습니다. REST 서비스는 귀하의 것입니까? 그렇다면 교차 간판 재가동을 활성화 했습니까? – JohnP
데이터 개체가 JSON이 아닙니다. –
그것에 대해 생각했지만 언급했듯이 Chrome/Firefox의 REST 클라이언트에서 작동했습니다. 그래서 나는 crossorigin 제한이 없어야한다고 믿습니다. 네, REST 서비스는 다른 도메인의 원격 서버에 있습니다. Tks! – Ralph