1
내 프로젝트에서는 ajax() jquery 함수로 비동기 호출로 캐시 된 이미지를 동적으로 표시하고 싶습니다.ajax() jquery 함수의 비동기 호출로 캐시에서 이미지 표시
$.ajax({
type: “POST”,
url: “mypage.aspx/GetThumbnail”,
data: “{‘id’:'" + idThumbnail + "’}”,
contentType: “application/json; charset=utf-8?,
dataType: “json”,
success: function(msg) {
// Hide the fake progress indicator graphic.
$('#thumbnailContent').removeClass('loading');
// Insert the returned HTML into the <div>.
$('#thumbnailContent').html(msg.d);
}
});
내의 WebMethod의 반환이 같은 HTML로 표시 할 수 있도록 성공 인 경우 비동기 적 정적의 WebMethod "mypage.aspx"페이지 "의 getThumbnail를"호출이 JQuery와 블록 코드 :
<img url="myThumbnailImage.jpg" />
내 문제는 문자열에 HTML 서식을 반환해야 정적의 WebMethod에서 온,하지만 난 캐시에서 데이터를 읽을 때 나는 []과 같이 바이트를 복구 :
이if (HttpContext.Current.Cache[id_thumbnail+ "_thumbnail"] != null)
{
byte[] mytemptabbyte = (byte[])HttpContext.Current.Cache[id_thumbnail + "_thumbnail"];
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "image/jpeg");
HttpContext.Current.Response.Write("");
HttpContext.Current.Response.BinaryWrite(mytemptabbyte);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
}
에게 retu을 할 수있는 방법 내 캐시 된 이미지에 대한 html 형식의 응답?
편집 :
그래서 내가 같이 할 수있는 새로운 aspx 페이지를 호출?function LoadThumnail(id_thumbnail){
$.ajax({
type: “POST”,
url: “getThumbnail.aspx?id_thumbnail=”id_thumbnail,
data: “{}”,
contentType: “application/json; charset=utf-8?,
dataType: “json”,
success: function(msg) {
// Insert the returned HTML into the <div>.
$('#thumbnailContent').html('<img src="' + msg.d + '" />);
// Hide the fake progress indicator graphic.
$('#thumbnailContent').removeClass('loading');
}
});
}
좋아요.하지만 이렇게하면 비동기 호출이 아니며 요청시 미리보기 이미지를로드하고 싶습니다 ... – bor1s
@ bor1s는 아약스에 의해 언급 된 페이지를 비동기 적으로 호출합니다. 아약스 요청은 항상 문자열 표현을 가져옵니다. – Igarioshka
사과와 배, 여러분. 그는 그의 ajax 호출이 img 태그 html로 간다고 말했다. 그 이미지가 존재하지 않기 때문에 메모리에있는 이미지 데이터를 활용할 수 있도록 마크 업을 변경하는 것이 좋습니다. 다른 방법으로는 이미지 데이터를 디스크에 저장 한 다음 정리에 대해 걱정할 필요없이 걱정할 필요가 없습니다. –