ajax 动态获取json的例子
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的例子的更多相关文章
- ECharts 环形饼图 动态获取json数据
ECharts 环形饼图 动态获取json数据 效果图如下: 一.html部分 <div id="secondPieChart" style="width:100 ...
- jquery通过ajax方法获取json数据不执行success
1.jquery通过ajax方法获取json数据不执行success回调 问题描述:jquery通过ajax方法获取json数据不执行success回调方法 问题原因:json格式存在问题或不符合标准 ...
- jquery通过ajax方法获取json数据不执行success回调
问题描述:jquery通过ajax方法获取json数据不执行success回调方法 问题原因:json格式存在问题或不符合标准写法,导致总是执行error回调方法 解决方案:使json格式务必符合下述 ...
- echarts通过ajax动态获取数据的方法
echarts表格的数据一般都需要动态获取,所以总结了一下通过ajax动态获取数据的操作: 插入的方法应该不止一种,我也是接触不久,所以刚学会了一种插入方法: 灵感和经验来自:https://www. ...
- 用ajax动态获取数据显示在highcharts上
html代码(index.html) <html><head> <meta charset="UTF-8" /> <title>Hi ...
- ajax模拟获取json
现在工作中我用到获取数据的方式,基本都是ajax.前台获取后端的数据后,需要进行处理,然后把他们放进页面中的相应标签里.下面举一个简单的例子,来模拟数据的获取和摆放. 这里用ng框架获取数据然后处理, ...
- 发送Ajax请求获取JSON格式数据
Aspx前端页面: <script type="text/javascript"> $(function () { $.getJSON("Ajax/TestA ...
- 利用autocomplete.js实现仿百度搜索效果(ajax动态获取后端[C#]数据)
实现功能描述: 1.实现搜索框的智能提示 2.第二次浏览器缓存结果 3.实现仿百度搜索 <!DOCTYPE html> <html xmlns="http://www.w3 ...
- jquery select 列表 ajax 动态获取数据 模糊查询 分页
最近需要一个这样的select 在网上找的多是数据一次性获取到再通过前端模糊查询匹配的 这样在数据量比较大的情况下不适合 ,所以参考http://www.jq22.com/jquery-info145 ...
随机推荐
- IIC,RS485,RS232各种协议手册更新中
RS485使用手册与指南.pdf RS232协议标准详解.pdf IIC通信协议.pdf 链接:http://pan.baidu.com/s/1ccBtmA 密码:mwj6 IIC,RS485,R ...
- MySQL中怎么对varchar类型排序问题
MySQL中怎么对varchar类型排序问题 在mysql默认order by 只对数字与日期类型可以排序,但对于varchar字符型类型排序好像没有用了,下面我来给各位同学介绍varchar类型排序 ...
- Map Columns From Different Tables and Create Insert and Update Statements in Oracle Forms
This is one of my most needed tool to create Insert and Update statements using select or alias from ...
- 权威发布:长链非编码RNA命名规则
转自:http://blog.sina.com.cn/s/blog_8088f3700101pab7.html 权威发布:长链非编码RNA命名规则 对于人类基因命名标准的制定而言,雨果基因命名委员会( ...
- [HDOJ5783]Divide the Sequence(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5783 题意:给n个数,要求划分成多个段,使得每一个段的任意前缀和都不小于0. 从后往前截取,这样不会影 ...
- Building,Packaging,Deploying,and Administering Applications and Types
buliding types into a module: response files: the IL disassembler:ILDasm.exe add assemblies to a pro ...
- linux配置IP地址
1. ifconfig命令临时配置IP地址 ifconfig命令:查看与配置网络状态命令 如: ifconfig eht0 192.168.0.200 netmask 255.255.255.0 # ...
- POJ 2376 Cleaning Shifts(轮班打扫)
POJ 2376 Cleaning Shifts(轮班打扫) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] Farmer ...
- XmlDocument To String
一.从String xml到XmlDocument的: string xml = "<XML><Test>Hello World</Test></X ...
- [转]-Android Studio 快捷键整理分享-SadieYu
文章编辑整理:Android Studio 中文组 - SadieYu Alt+回车 导入包,自动修正 Ctrl+N 查找类 Ctrl+Shift+N 查找文件 Ctrl+Alt+L 格式化代码 ...