后台代码:

public void findByIDEquipment() {
getResponse().setCharacterEncoding("UTF-8");
getResponse().setContentType("text/html;charset=UTF-8");
PrintWriter out;
JSONObject obj = new JSONObject();
JSONArray jarr = new JSONArray();
ArrayList<Equipment> eq_array_list = new ArrayList<Equipment>();
SimpleDateFormat sdf = new SimpleDateFormat();
try {
out = getResponse().getWriter(); System.out.println(eq_id); long id = Long.valueOf(getRequest().getParameter("eq_id"));
System.out.println("id is" + id);
Equipment eq = eq_service.findEquipmentById(id);
Equipment eq1 = eq;
eq_array_list.add(eq);
if (eq != null) {
/*
* getSession().setAttribute("eq_name", eq.getName());
* getSession().setAttribute("eq_comment", eq.getComment());
* getSession().setAttribute("eq_pn", eq.getPn());
* getSession().setAttribute("eq_sn", eq.getSn());
* getSession().setAttribute("eq_inDate", eq.getInDate());
* getSession().setAttribute("eq_alarmDay",
* eq.getAlarmTimeDay());
* getSession().setAttribute("eq_overTime", eq.getOverTime());
* getSession().setAttribute("eq_username",
* eq.getEq_user().getUsername());
*/
obj.put("eq1", eq1);
obj.put("indate", sdf.format(eq1.getInDate()));
obj.put("overdate", sdf.format(eq1.getOverTime()));
jarr.add(obj); out.print(jarr);
out.flush(); } else {
out.println(false);
} } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }

前台代码:

/* 详情动作 */
$('.action_div')
.click(
function() {
var click_num = $('.action_div').index(this)
console.log(click_num)
var eq_id = $('.action_div').eq(click_num).attr('org')
console.log("select item id is" + eq_id) $.ajax({
type : "POST",
url : "findByIDEquipmentAction?fresh="
+ Math.random(),
data : {
"eq_id" : eq_id
},
cache : false,
async : true,
dataType : "json",
success : function(res) {
console.log(res)
console.log(res[0].eq1.name) if (res) { $('.getname').text(res[0].eq1.name)
$('.getcomment').text(res[0].eq1.comment)
$('.getpn').text(res[0].eq1.pn)
$('.getsn').text(res[0].eq1.sn)
$('.getindate').text(
res[0].indate.toString().substring(
0, 8))
$('.getalarmday').text(
res[0].eq1.alarmTimeDay)
$('.getoverdate').text(
res[0].overdate.toString()
.substring(0, 8))
$('.getusername').text(
res[0].eq1.eq_user.username) } else {
alert("请求异常1");
} },
error : function(json) {
alert("请求异常2");
}
}) $('#mask2')
.css(
{
"opacity" : "1",
"z-index" : "100",
'-webkit-transition' : 'opacity 2s ease-in,z-index 1s ease-in',
'-moz-transition' : 'opacity 2s ease-in,z-index 1s ease-in',
'-ms-transition' : 'opacity 2s ease-in,z-index 1s ease-in',
'-o-transition' : 'opacity 2s ease-in,z-index 1s ease-in',
'transition' : 'opacity 2s ease-in,z-index 1s ease-in' }) })

  

public void findByIDEquipment() {getResponse().setCharacterEncoding("UTF-8");getResponse().setContentType("text/html;charset=UTF-8");PrintWriter out;JSONObject obj = new JSONObject();JSONArray jarr = new JSONArray();ArrayList<Equipment> eq_array_list = new ArrayList<Equipment>();SimpleDateFormat sdf = new SimpleDateFormat();try {out = getResponse().getWriter();
System.out.println(eq_id);
long id = Long.valueOf(getRequest().getParameter("eq_id"));System.out.println("id is" + id);Equipment eq = eq_service.findEquipmentById(id);Equipment eq1 = eq;eq_array_list.add(eq);if (eq != null) {/* * getSession().setAttribute("eq_name", eq.getName()); * getSession().setAttribute("eq_comment", eq.getComment()); * getSession().setAttribute("eq_pn", eq.getPn()); * getSession().setAttribute("eq_sn", eq.getSn()); * getSession().setAttribute("eq_inDate", eq.getInDate()); * getSession().setAttribute("eq_alarmDay", * eq.getAlarmTimeDay()); * getSession().setAttribute("eq_overTime", eq.getOverTime()); * getSession().setAttribute("eq_username", * eq.getEq_user().getUsername()); */obj.put("eq1", eq1);obj.put("indate", sdf.format(eq1.getInDate()));obj.put("overdate", sdf.format(eq1.getOverTime()));jarr.add(obj);
out.print(jarr);out.flush();
} else {out.println(false);}
} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}
}

前后台数据交换,printwriter、jsonobject、jsonarray、ajax请求,数据交换的更多相关文章

  1. session失效,使用ajax请求数据被拦截,此时正常的处理逻辑是跳到登录界面,而不是界面没有变化(java推断是否是ajax请求)

    在登录过滤器中.推断请求是ajax请求还是超链接或者地址栏变化的请求 if (httpServletReq.getHeader("x-requested-with") != nul ...

  2. dotnet webservice处理数据量过大,ajax请求返回500错误解决方案

    ajax请求webservice返回json数据,数据规模过大时ajax请求会得到500的响应,webservice+ajax处理大规模的数据需要在web.config中进行如下配置: <sys ...

  3. 关于ajax请求数据,并将数据赋值给全局变量的一些解决方法

    在使用ajax请求数据是,开始的时候是打算将ajax的数据取出,并赋予给全局变量,但是在实际编码过程中发现并不能将数据赋予给最开始定义的全局变量,出现这个问题的原因是由于ajax异步加载的原因,所以只 ...

  4. vue使用element Transfer 穿梭框实现ajax请求数据和自定义查询

    vue使用element Transfer 穿梭框实现ajax请求数据和自定义查询 基于element Transfer http://element-cn.eleme.io/#/zh-CN/comp ...

  5. Ajax请求数据的两种方式

    ajax 请求数据的两种方法,有需要的朋友可以参考下. 实现ajax 异步访问网络的方法有两个.第一个是原始的方法,第二个是利用jquery包的 原始的方法不用引入jquery包,只需在html中编写 ...

  6. Ajax请求数据与删除数据后刷新页面

    1.ajax异步请求数据后填入模态框 请求数据的按钮(HTML) <a class="queryA" href="javascript:void(0)" ...

  7. ajax 请求数据的两种方法

    实现ajax 异步访问网络的方法有两个.第一个是原始的方法,第二个是利用jquery包的 原始的方法不用引入jquery包,只需在html中编写script 片段 这里我演示的是一个传递参数查询的例子 ...

  8. h5-localStorage实现缓存ajax请求数据

    使用背景:要实现每次鼠标hover“能力雷达”,则显示能力雷达图(通过ajax请求数据实现雷达图数据显示),所以每次hover都去请求ajax会影响性能,因此这里要用到本地缓存. 实现: 此处是通过传 ...

  9. 使用Python的Flask框架,结合Highchart,动态渲染图表(Ajax 请求数据接口)

    参考链接:https://www.highcharts.com.cn/docs/ajax 参考链接中的示例代码是使用php写的,这里改用python写. 需要注意的地方: 1.接口返回的数据格式,这个 ...

  10. 关于ajax请求数据后,数据本身的js失效的一些想法

    今天遇到一个头疼的问题.我做一个左右翻页效果(客户要求能够无限翻页),所以只能动态请求数据,进行局部刷新操作. 这时候问题就出来了,当我请求翻页的时候,数据通过js填充到div里面,但这些数据,自身带 ...

随机推荐

  1. python学习笔记3-函数

    一.函数高级特性 1)列表生成式,列表生成式即List Comprehensions,是Python内置的非常简单却强大的可以用来创建list的生成式. eg: >>> list(r ...

  2. 【原创】Arduino制作Badusb实践

    1.U盘构造      U盘由芯片控制器和闪存两部分组成. 芯片控制器负责与PC的通讯和识别,闪存用来做数据存储: 闪存中有一部分区域用来存放U盘的固件,它的作用类似于操作系统,控制软硬件交互:固件无 ...

  3. VS2017 nlog源码查看报错

    最近下载nlog的源码学习,打开解决方案以后无法编译. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sd ...

  4. Ubuntu软件中心闪退

    sudo apt-get update sudo apt-get dist-upgrade sudo apt-get install --reinstall software-center

  5. SQL设置时间格式

    SELECT STR_TO_DATE('Jul 20 2013 7:49:14:610AM','%b %d %Y %h:%i:%s:%f%p') from DUAL; -- 执行后得到结果:'2013 ...

  6. 【消息中间件之RabbitMQ学习】-开篇-001

    写在前面的话 项目中因为要用到消息中间件,当初极力推荐RabbitMq.但因为种种原因,最终选型为java+mongodb自实现一套分布式的消.没有用RabbitMq工作过,实属遗憾.因为个人来说实在 ...

  7. 不使用循环或递归判断一个数是否为3的幂(leetcode 326)

    326. Power of ThreeGiven an integer, write a function to determine if it is a power of three. Follow ...

  8. 小妖精的完美游戏教室——东方PROJECT,同人,th12灵梦A

    ╮(╯▽╰)╭没办法,小妖精Balous也很讨厌学院化的教育呀,一点意义都没有. 这次就上传东方地灵殿灵梦A逻辑部分的核心代码吧,估计连老师都看不懂.动画部分的代码就不放上来了. //======== ...

  9. eclipse通过maven进行打编译

    对maven项目中pom.xml右键-->Run As-->Maven build... Goals里面添加assembly:assembly 点击run,编译成功后jar包在target ...

  10. unity 面试题(答案)

    一.什么是渲染管道?是指在显示器上为了显示出图像而经过的一系列必要操作.渲染管道中的很多步骤,都要将几何物体从一个坐标系中变换到另一个坐标系中去.主要步骤有:本地坐标->视图坐标->背面裁 ...