在jquery下翻看图片,如何判断最后一张呢?
16lz
2021-01-22
本人初学做了一个效果,就是一张张翻看相册照片,使用了jquery构架下的ajax(不专业别见笑),应该翻到最后一张时,再翻就显示:没有图片了。可我的不是这样,还能续继翻但就报错了。
以下是ashx里的内容:
以下是前台内容:
上面的代码可运行,只是翻到最后一页后会出错,本人不知如何应对,请高手们指导
你把错误处理成没有图片了的提示就行了
以下是ashx里的内容:
<%@WebHandlerLanguage="C#"Class="turnpagepic"%>
usingSystem;
usingSystem.Web;
usingSystem.Data;
usingSystem.Text;
usingSystem.Data.OleDb;
using_tjhdtx;
publicclassturnpagepic:IHttpHandler
{
stringchannel=string.Empty;
stringlanmu=string.Empty;
stringssql=string.Empty;
intid;
stringact=string.Empty;
publicvoidProcessRequest(HttpContextcontext)
{
context.Response.ContentType="text/plain";
context.Response.Clear();
channel=context.Request.Form["channel"];
lanmu=context.Request.Form["lanmu"];
id=int.Parse(context.Request.Form["id"]);
act=context.Request.Form["action"];
if(act.CompareTo("pre")==0)
{
ssql="SELECTid,title,description,watermarkimage,[count],[update]FROMtukuWHEREid=(SELECTmax(id)FROMtukuWHEREid<"+id+"andlanmu='"+lanmu+"'andchannel='"+channel+"')";
}
elseif(act.CompareTo("next")==0)
{
ssql="SELECTid,title,description,watermarkimage,[count],[update]FROMtukuWHEREid=(SELECTmin(id)FROMtukuWHEREid>"+id+"andlanmu='"+lanmu+"'andchannel='"+channel+"')";
}
elseif(act.CompareTo("cur")==0)
{
ssql="SELECTid,title,description,watermarkimage,[count],[update]FROMtukuWHEREid="+id;
}
DataTabledt=newDataTable();
dt=DBS.reDatatable(ssql);
if(dt.Rows.Count>0)
{
DataRowdr=dt.Rows[0];
stringjsonString=JsonHelper.DataRowToJson(dr);
context.Response.Write(jsonString);
}else{
context.Response.Write("{\"id\":\"\",\"title\":\"\",\"description\":\"\",\"watermarkimage\":\"\",\"count\":\"\",\"update\":\"\"}");
}
}
publicboolIsReusable{
get{
returnfalse;
}
}
}
以下是前台内容:
<scriptlanguage="JavaScript"type="text/javascript">
QueryString={
data:{},
Initial:function(){
varaPairs,aTmp;
varqueryString=newString(window.location.search);
queryString=queryString.substr(1,queryString.length);//remove"?"
aPairs=queryString.split("&");
for(vari=0;i<aPairs.length;i++){
aTmp=aPairs[i].split("=");
this.data[aTmp[0]]=aTmp[1];
}
},
GetValue:function(key){
returnthis.data[key];
}
}
//先初始化
QueryString.Initial();
var$channel=QueryString.GetValue('channel');
var$lanmu=QueryString.GetValue('lanmu');
var$id=QueryString.GetValue('id');
var$pid;
functiongetBrowse($pid,act)
{
switch(act){
case"pre":
curact="pre";
break;
case"next":
curact="next";
break;
default:
curact="cur"
break;
}
$("#picshow").empty();
$.ajax({
url:"handler/tukupic.ashx",
type:"POST",
dataType:"json",
data:{"channel":$channel,"lanmu":$lanmu,"id":$pid,"action":curact},
success:function(data){
// data=$.parseJSON(data);
// alert(data);
// if(data!="allgone"){
$.each(data,function(index,item){
OutputData(item);
})
// }
// else
// {
// alert("已经没有图片了");
// return;
// }
},
error:function(XMLHttpRequest,textStatus,errorThrown){
alert(XMLHttpRequest.status);
//alert(textStatus);
}
})
}
functionOutputData(item){
if(item["title"]!=""){
document.getElementById("titleshow").innerHTML=item["title"];
// alert($id);
// document.getElementById("titleshow").innerHTML=item["hit"];
document.getElementById("picshow").innerHTML="<imgsrc=\""+item["watermarkimage"]+"\"width=\"600\"height=\"400\"/>";
document.getElementById("buttonshow").innerHTML="<ahref=\"javascript:void(0)\"onclick=\"getBrowse("+item["id"]+",'pre'"+")\"><imgsrc=\"images/previous.jpg\"/></a> "+
"<ahref=\"javascript:void(0)\"onclick=\"getBrowse("+item["id"]+",'next'"+")\"><imgsrc=\"images/next.jpg\"/></a>";
}else
alert("没有图片了");
}
$(document).ready(function(){
getBrowse($id,"cur");
// $("#loading").bind("ajaxStart",function(){
// $("#showarea").html("");
// $(this).show();
// }).bind("ajaxStop",function(){
// $(this).hide();
// });
})
</script>
上面的代码可运行,只是翻到最后一页后会出错,本人不知如何应对,请高手们指导
3 个解决方案
#1
你把错误处理成没有图片了的提示就行了
更多相关文章
- 使用javascript进行内容占位符问题的第二个css
- 通过AJAX加载内容和预加载图像?
- 是否每次都可能分离内容、表示和行为?
- 使用JQuery从外部文件中通过id选择器获取html内容
- jQuery autocomplete:如何在结果中选择某些内容后调用getJson?
- Jquery 特效 图片轮转 菜单
- ajax cache false无法加载图片
- jQuery 点击div, 向上展示内容
- Ajax/jQuery -在页面加载时将网页内容加载到div中?