jQuery.ajaxTransport ()
jQuery.ajaxTransport ()
설명 : Ajax 데이터의 실제 전송을 처리하는 객체를 생성합니다.
이 전송은 두 가지 방법을 제공 목적 send과 abort내부에서 사용되며, $.ajax()문제 요청한다. 전송은 개선 할 수있는 가장 진보 된 방법이며, $.ajax()프리 필터 및 변환기가 불충분 할 때 마지막 수단으로 만 사용해야합니다.
각 요청에는 고유 한 전송 오브젝트 인스턴스가 필요하기 때문에 전송을 직접 등록 할 수 없습니다. 따라서 대신 전송을 반환하는 함수를 제공해야합니다.
전송 팩토리는을 (를) 사용하여 등록됩니다 $.ajaxTransport(). 일반적인 등록은 다음과 같습니다.
$.ajaxTransport( dataType, function( options, originalOptions, jqXHR ) {
if( /* transportCanHandleRequest */ ) {
return {
send: function( headers, completeCallback ) {
// Send code
},
abort: function() {
// Abort code
}
};
}
});
1. op$.ajaxTransport( "image", function( s ) {
if ( s.type === "GET" && s.async ) {
var image;
return {
send: function( _ , callback ) {
image = new Image();
function done( status ) {
if ( image ) {
var statusText = ( status === 200 ) ? "success" : "error",
tmp = image;
image = image.onreadystatechange = image.onerror = image.onload = null;
callback( status, statusText, { image: tmp } );
}
}
image.onreadystatechange = image.onload = function() {
done( 200 );
};
image.onerror = function() {
done( 404 );
};
image.src = s.url;
},
abort: function() {
if ( image ) {
image = image.onreadystatechange = image.onerror = image.onload = null;
}
}
};
}
});tions 요청 옵션입니다.
2. originalOptions$.ajax()ajaxSettings의 기본값없이 메소드에 제공되는 옵션입니다.
3. jqXHR 요청의 jqXHR 객체입니다.
4. headers 전송 장치가 지원할 경우 전송할 수있는 (키 - 값) 요청 헤더의 개체입니다.
5. completeCallback Ajax에 요청 완료를 알리는 데 사용되는 콜백이다.
completeCallback 다음 서명이 있습니다.
function( status, statusText, responses, headers ) {}
$.ajaxTransport( "script", function( options, originalOptions, jqXHR ) {
// Will only be called for script requests
});
다음 예제는 최소 이미지 전송을 구현하는 방법을 보여줍니다.
게시판 목록
개발자팁
질문은 QA에서 해주시기 바랍니다.
| 번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|---|
| 4736 | jQuery | 8년 전 | 1559 | ||
| 4735 | jQuery | 8년 전 | 1747 | ||
| 4734 | jQuery | 8년 전 | 1737 | ||
| 4733 | jQuery | 8년 전 | 2033 | ||
| 4732 | jQuery | 8년 전 | 1955 | ||
| 4731 | jQuery | 8년 전 | 1459 | ||
| 4730 | jQuery | 8년 전 | 1917 | ||
| 4729 | PHP |
|
8년 전 | 6898 | |
| 4728 | jQuery | 8년 전 | 2562 | ||
| 4727 | jQuery | 8년 전 | 1610 | ||
| 4726 | jQuery | 8년 전 | 1690 | ||
| 4725 | jQuery | 8년 전 | 1834 | ||
| 4724 | jQuery | 8년 전 | 1310 | ||
| 4723 | jQuery | 8년 전 | 1862 | ||
| 4722 | jQuery | 8년 전 | 1625 | ||
| 4721 | jQuery | 8년 전 | 1917 | ||
| 4720 | jQuery | 8년 전 | 1975 | ||
| 4719 | jQuery | 8년 전 | 1601 | ||
| 4718 | jQuery | 8년 전 | 1607 | ||
| 4717 | jQuery | 8년 전 | 1558 | ||
| 4716 | jQuery | 8년 전 | 1236 | ||
| 4715 | jQuery | 8년 전 | 1394 | ||
| 4714 | jQuery | 8년 전 | 1415 | ||
| 4713 | jQuery | 8년 전 | 1334 | ||
| 4712 | jQuery | 8년 전 | 2227 | ||
| 4711 | jQuery | 8년 전 | 1712 | ||
| 4710 | PHP |
|
8년 전 | 3747 | |
| 4709 | jQuery | 8년 전 | 1629 | ||
| 4708 | jQuery | 8년 전 | 1909 | ||
| 4707 | jQuery | 8년 전 | 1761 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기