1、前台脚本:

//用于切换图片列表的ajax
function changePhoto(title,hotelId){
$.ajax({
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
type : "post",
url : "<@a.webRoot/>/base/bms/hotel/hotelPicture-queryPictureByTitleAjax.action",
data : {
"hotelPicturePage.hotelPicture.title" : title,
"hotelPicturePage.hotelPicture.hotelId" : hotelId
},
dataType : "json",
success : function(data) {
//先将小图的内容替换
var hotelPictureList = data.hotelPcitureList;
if(hotelPictureList !='undefined' && hotelPictureList!= null && hotelPictureList.length >0 ){
var htmlStr = '<tr>', imgTitle = "", imgUrl = "";
for(var i = 0;i < hotelPictureList.length;i++){
imgTitle = hotelPictureList[i].title;
imgUrl = hotelPictureList[i].imgUrl;
htmlStr += '<td originalPhoto="'+imgUrl+'"><img src="'+imgUrl+'" title="'+imgTitle+'" height="75" alt="'+imgTitle+'" width="100" name="imgUrl"></td>';
}
htmlStr += '</tr>';
$("#hotelPictureContainer").html(htmlStr);//赋予table新的内容
$("#hotelPictureContainer").removeAttr("style");//清除之前小图滑动产生的样式 //然后使用第一张小图替换大图
if(hotelPictureList[0].imgUrl != null && hotelPictureList[0].imgUrl != 'undefined'){//判断下小图是否存在
$("#originalPhoto").attr("src",hotelPictureList[0].imgUrl);
} //最后激活各个小图的点击替换大图
$("#thumbContainer td").click(function(){
alert(22);
var tdObj = $(this);
photoIndex = $("#thumbContainer td").index(tdObj);
$("#originalPhoto").attr("src",tdObj.attr("originalPhoto"));
$("#photoContainer").css("width",($("#originalPhoto").width())+"px");
}); //更新小图的区的数据
photoCount = $("#thumbContainer img").length;//图片数量
leftCount = Math.ceil(photoCount / 5);//分页数量
leftLevel = 0;//分页级数
photoIndex = 0;//图片序号 }
else{
alert("抱歉,该酒店暂无相关图片。");
}
},
error : function(){
alert("数据错误,请稍后再试。");
}
});
};

2、后台java代码:

public void queryPictureByTitleAjax(){
//先过滤下页面传回的Title为""好"null"的问题
if(hotelPicturePage.getHotelPicture() != null ){
if("".equals(hotelPicturePage.getHotelPicture().getTitle()) || "null".equals(hotelPicturePage.getHotelPicture().getTitle())){
hotelPicturePage.getHotelPicture().setTitle(null);
}
}
JSONObject jsobject = new JSONObject();
//获取需要的图片
hotelPicturePage = hotelPictureService.queryHotelPictureByTitle(commonPage, hotelPicturePage);
if (hotelPicturePage.getHotelPictureList() == null||hotelPicturePage.getHotelPictureList().size()<=0) {
jsobject.put("hotelPcitureList", null);
}
else {//封装json数据
List<HotelPicture> hotelPcitureList = hotelPicturePage.getHotelPictureList();
List<JSONObject> jsonList = new ArrayList<JSONObject>();
for(int i = 0;i < hotelPcitureList.size();i++){
JSONObject item = new JSONObject();
item.put("title", hotelPcitureList.get(i).getTitle());
item.put("imgUrl", hotelPcitureList.get(i).getImgUrl());
jsonList.add(item);
}
jsobject.put("hotelPcitureList", jsonList);
}
writeJson(jsobject);
}

ajax 动态获取json的例子的更多相关文章

  1. ECharts 环形饼图 动态获取json数据

    ECharts  环形饼图 动态获取json数据 效果图如下: 一.html部分 <div id="secondPieChart" style="width:100 ...

  2. jquery通过ajax方法获取json数据不执行success

    1.jquery通过ajax方法获取json数据不执行success回调 问题描述:jquery通过ajax方法获取json数据不执行success回调方法 问题原因:json格式存在问题或不符合标准 ...

  3. jquery通过ajax方法获取json数据不执行success回调

    问题描述:jquery通过ajax方法获取json数据不执行success回调方法 问题原因:json格式存在问题或不符合标准写法,导致总是执行error回调方法 解决方案:使json格式务必符合下述 ...

  4. echarts通过ajax动态获取数据的方法

    echarts表格的数据一般都需要动态获取,所以总结了一下通过ajax动态获取数据的操作: 插入的方法应该不止一种,我也是接触不久,所以刚学会了一种插入方法: 灵感和经验来自:https://www. ...

  5. 用ajax动态获取数据显示在highcharts上

    html代码(index.html) <html><head> <meta charset="UTF-8" /> <title>Hi ...

  6. ajax模拟获取json

    现在工作中我用到获取数据的方式,基本都是ajax.前台获取后端的数据后,需要进行处理,然后把他们放进页面中的相应标签里.下面举一个简单的例子,来模拟数据的获取和摆放. 这里用ng框架获取数据然后处理, ...

  7. 发送Ajax请求获取JSON格式数据

    Aspx前端页面: <script type="text/javascript"> $(function () { $.getJSON("Ajax/TestA ...

  8. 利用autocomplete.js实现仿百度搜索效果(ajax动态获取后端[C#]数据)

    实现功能描述: 1.实现搜索框的智能提示 2.第二次浏览器缓存结果 3.实现仿百度搜索 <!DOCTYPE html> <html xmlns="http://www.w3 ...

  9. jquery select 列表 ajax 动态获取数据 模糊查询 分页

    最近需要一个这样的select 在网上找的多是数据一次性获取到再通过前端模糊查询匹配的 这样在数据量比较大的情况下不适合 ,所以参考http://www.jq22.com/jquery-info145 ...

随机推荐

  1. COGS502. 长路上的灯

    502. 长路上的灯 ☆   输入文件:light.in   输出文件:light.out   简单对比时间限制:1 s   内存限制:128 MB [题目描述] 在一条无限长的路上,有一排无限长的路 ...

  2. FileInputstream的available()方法

    摘自:http://greemranqq.iteye.com/blog/2051487

  3. CodeForces 628B New Skateboard

    New Skateboard time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. UVA 1252 十五 Twenty Questions

    十五 Twenty Questions Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submi ...

  5. CodeForces 151B Phone Numbers

     Phone Numbers Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Sub ...

  6. FastReport处理空日期

    [IIf([D.ApproveDate]==DateTime.MinValue,"",[D.ApproveDate])]

  7. c#扩展方法的理解(一:初识)

    扩展方法是静态方法,是类的一部分,但是实际上没有放在类的源代码中. 扩展方法所在的类也必须被声明为static C#只支持扩展方法,不支持扩展属性.扩展事件等. 扩展方法的第一个参数是要扩展的类型,放 ...

  8. ABAP Enhancement:第二部分

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  9. ubuntu14.04配置静态IP地址

    1. 找到文件并作如下修改:vim /etc/network/interfaces修改如下部分:# interfaces(5) file used by ifup(8) and ifdown(8)au ...

  10. 数据库分库分表(sharding)

    地址: http://blog.csdn.net/column/details/sharding.html