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. Storm系列之二——Guaranteeing Message Processing

    Storm保证每跳离开spout的消息都会被完全处理.本文介绍Storm是怎么保证每条消息都被完全处理并且作为用户该怎么做才能从Storm的可靠性保证受益. 1.什么叫消息被完全处理? 一个tuple ...

  2. c语言中函数调用的本质从汇编角度分析

    今天下午写篇博客吧,分析分析c语言中函数调用的本质,首先我们知道c语言中函数的本质就是一段代码,但是给这段代码起了一个名字,这个名字就是他的的这段代码的开始地址 这也是函数名的本质,其实也就是汇编中的 ...

  3. 1-NPM

    什么是NPM NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题. 常见的使用场景有以下几种: 允许用户从NPM服务器下载别人编写的第三方包到本地使用. 允许用户从N ...

  4. size()弃用

    size() 方法在 jQuery 版本 1.8 中被废弃. 请使用 length 属性代替.

  5. sql去除某个字段中的某个字符串 replace

    update A set col1 =REPLACE ( col1 ,'测试' , '') where col1 like '%测试%' 在使用过程中如果遇到text类型的字段时会报 参数数据类型 t ...

  6. Python3基础 逻辑与 and

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  7. Cheatsheet: 2013 08.01 ~ 08.13

    Mobile Objective C Blocks: Summary, Syntax & Best Practices Android SDK: Create an Arithmetic Ga ...

  8. Populating Tabular Data Block Manually Using Cursor in Oracle Forms

    Suppose you want to populate a non-database data block with records manually in Oracle forms. This t ...

  9. SpringMVC 使用Form标签库制作登录表单

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  10. 将文件读取到内存、打印pe结构

    #include <stdio.h> #include <malloc.h> #include <stdlib.h> #include <string.h&g ...