Php 用ajax加载fadein图像
我使用这个ajax代码来显示选择图像Php 用ajax加载fadein图像,php,jquery,ajax,Php,Jquery,Ajax,我使用这个ajax代码来显示选择图像 function get_image(id) { var getid=id; var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Micros
function get_image(id)
{
var getid=id;
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("in-t").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","<?php echo get_template_directory_uri(); ?>/class/class.image.php?id=" + getid + "&tnow="+ (new Date()).getTime(),true);
xmlhttp.send();
}
函数获取图像(id)
{
var getid=id;
var-xmlhttp;
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“in-t”).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”、“/class/class.image.php?id=“+getid+”&tnow=“+(new Date()).getTime(),true);
xmlhttp.send();
}
当用户单击缩略图时,首先加载.gif显示,然后在in-t id中显示大图像。但我想第一个完整的加载图像,所以显示。我找到了jquery加载函数,但我不知道如何使用它???如果您在代码中使用jquery会更好。在标题中包括以下行
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
并重写函数get_image,如下所示
function get_image(id) {
var getid=id;
$("#idOfResultDiv").html('<img src="yourloading.gif" />');
$.ajax({
type: 'GET',
async: false,
url: '<?php echo get_template_directory_uri(); ?>/class
/class.image.php?id=' + getid + '&tnow='+ (new Date()).getTime(),true,
data: str,
success: function(response) {
$("#idOfResultDiv").html(response);
}
});
}
函数获取图像(id){
var getid=id;
$(“#idOfResultDiv”).html(“”);
$.ajax({
键入:“GET”,
async:false,
url:'/class
/class.image.php?id='+getid+'&tnow='+(新日期()).getTime(),true,
数据:str,
成功:功能(响应){
$(“#idOfResultDiv”).html(回复);
}
});
}
fadein在哪里?获取图像的唯一方法是最初隐藏div idOfResultDiv并更改行$(“#idOfResultDiv”).html(“”);作为$(“.idOfResultDiv”).html(“”).fadeIn();对不起:(我不知道你的意思。我想当响应pic完成加载,然后pic fadein。$(“#idOfResultDiv”).hide();$(“#idOfResultDiv”).html(响应)。fadein();当使用此代码时,先加载fadein,然后加载图像,但我想先加载完整的pic fadein。你能给我示例吗?