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. anroid

    http://mirrors.neusoft.edu.cn/more.we#android http://www.cnblogs.com/youxilua/archive/2013/05/20/308 ...

  2. [cdoj843] 冰雪奇缘 (线段树+离散)

    [线段树 + 离散化] Description 艾莎女王又开始用冰雪魔法盖宫殿了. 她决定先造一堵墙,于是释放魔法让形为直角梯形的冰砖从天而降,定入冻土之中. 现在你将回答女王的询问:某段冻土上冰砖的 ...

  3. pt-query-digest怎么分析慢查询日志分析数据

    在进行使用linux系统作为服务器的情况,那几需要进行对linux的服务器进行性能上数据进行抓取之后,就需要对数据中内容进行分析,看数据库中内容是否存在瓶颈上的问题,在进行获取到的数据的慢查日志,将使 ...

  4. An Example of Pre-Query and Post-Query Triggers in Oracle Forms With Using Display_Item to Highlight Dynamically

    Example is given for Pre-Query and Post-Query triggers in Oracle Forms, with using Display_Itembuilt ...

  5. .Net需要掌握的知识

    一.C#开发 1.C#基础 变量定义 如何变量的初始化 变量的作用域 常量 字符串处理 使用正则表达式 什么是CTS类型?数据类型如何分类以及各个数据类型范围 类型的转化分类 显式转换何隐式转化如何区 ...

  6. [51NOD1393]0和1相等串(前缀和,map)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1393 题意:中文题面. 把0看成是-1,并且存一遍前缀和.这样 ...

  7. git sshkeygen Fingerprint cannot be generated解决方法

    ssh-keygen -t rsa -C "xxx@xxx.com"   生成后使用cat或者vim 查看该rsa,然后复制到github的ssh keys中:     提示:   ...

  8. So easy Webservice 4.Java方式访问WebService(使用jdk1.6以上 wsimport命令)

    1.选中要调用的服务单击”服务说明” 2.获取wsdl文件.使用JDK1.6以上的版本的wsimport命令 a) 例如选中:http://webservice.webxml.com.cn/WebSe ...

  9. strange error encountered today in ROS

    I reinstalled my ubuntu system and also ROS. I tested slam_karto package when some strange error cam ...

  10. Fiddler界面详解

    Statistics 页签 完整页签如下图: Statistics 页签显示当前用户选择的 Sessions 的汇总信息,包括:选择的 Sessions 总数.发送字节数.接收字节数.响应类型的汇总表 ...