반응형
jQuery AJAX GET 호출에서 요청 헤더 전달
jQuery를 사용하여 AJAX GET에서 요청 헤더를 전달하려고 합니다.다음 블록에서 "data"는 쿼리 문자열의 값을 자동으로 전달합니다.그 데이터를 요청 헤더에 대신 전달할 수 있는 방법이 있습니까?
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: { signature: authHeader },
type: "GET",
success: function() { alert('Success!' + authHeader); }
});
다음도 작동하지 않았습니다.
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
beforeSend: { signature: authHeader },
async: false,
type: "GET",
success: function() { alert('Success!' + authHeader); }
});
jQuery 1.5에서는headers
다음과 같이 전달할 수 있습니다.
$.ajax({
url: "/test",
headers: {"X-Test-Header": "test-value"}
});
http://api.jquery.com/jQuery.ajax 에서 :
headers (1.5 추가): 요구와 함께 송신하는 추가 헤더 키/값 쌍의 맵.이 설정은 beforeSend 함수를 호출하기 전에 설정됩니다.따라서 헤더 설정의 값은 beforeSend 함수 내에서 덮어쓸 수 있습니다.
사용하다beforeSend
:
$.ajax({
url: "http://localhost/PlatformPortal/Buyers/Account/SignIn",
data: { signature: authHeader },
type: "GET",
beforeSend: function(xhr){xhr.setRequestHeader('X-Test-Header', 'test-value');},
success: function() { alert('Success!' + authHeader); }
});
http://api.jquery.com/jQuery.ajax/
http://www.w3.org/TR/XMLHttpRequest/ #set-requestheader-displays
$.ajax({
url: URL,
type: 'GET',
dataType: 'json',
headers: {
'header1': 'value1',
'header2': 'value2'
},
contentType: 'application/json; charset=utf-8',
success: function (result) {
// CallBack(result);
},
error: function (error) {
}
});
언급URL : https://stackoverflow.com/questions/3258645/pass-request-headers-in-a-jquery-ajax-get-call
반응형
'prosource' 카테고리의 다른 글
svn: E000002:커밋 실패 (0) | 2023.02.22 |
---|---|
jQuery.ajax() 메서드의 비동기 옵션이 폐지되었습니다.이제 어떻게 해야 하나요? (0) | 2023.02.22 |
비ASC 검색 및 삭제Oracle Varchar2의 II 문자 (0) | 2023.02.22 |
Play Framework - JSON 개체에 필드 추가 (0) | 2023.02.22 |
서비스에 주석을 달아 @Retention, @Transactional, @Inherited로 테스트한 후 테스트 NG 유닛 테스트가 작동하지 않음 (0) | 2023.02.22 |