ajax将json写到table中去
查询条件:
<table style="width: 100%;border-collapse: collapse;" >
<tr>
<th style="width: 15%;">分 类:</th>
<td style="width: 35%">
<input id="source_detail" name="source_detail" class="zxui-combotree">
</td>
<th style="width: 15%;">任务状态:</th>
<td style="width: 35%">
<input type="radio" name="z-status" id="z-all" checked="" value=''>全部
<input type="radio" name="z-status" id="z-normal" value='1'>正常
<input type="radio" name="z-status" id="z-pro-overdue" value='2'>可能超期
<input type="radio" name="z-status" id="z-overdue" value='3'>超期
</td>
</tr>
<tr>
<th>名 称:</th>
<td colspan="3">
<input id="serchname" class="zxui-textbox" style="width: 80%;">
<a href="javascript:search()" class="zxui-linkbutton" data-options="iconCls:'icon-search'" style="width:80px;line-height:22px;">筛 选</a>
</td>
</tr>
</table>
ajax:
(注意:在js中以var定义变量,赋值给另一变量作为条件是的以用语法 “ ‘+var+’ ”
例如:
‘<img title="" class="light" src=" '+msgid+' "/>’ 因为ajax返回json不能直接写入到table中去,需要判断转换为url路径放入到table中的图片中去,我先对json值做了判断,根据值的不同,给msgid赋值不同,再写入图片标签的src中去, 因为语法问题在这里饶了好长时间。在一变量的形式给html解析页面时,变量里的html标签用“”引起来,颜色为蓝色,如果便签内出现了“”是要\转译的,否则报错。
)
function search(mygz,acceptoridif,acceptorid){
var code =$("#source_detail").combotree("getValue");
var title =$("#serchname").val();
var waring = $("input[name='z-status']:checked").val();
var taskid = $().val;
$.ajax({
type : "post",
url : "${ctx}/control/first_Like.pt",
data : {code:code,waring:waring,title:title,mygz:mygz,acceptoridif:acceptoridif,acceptorid:acceptorid},
success : function(json){
$('#biaodan tr:gt(0)').remove();//删除之前的数据
for (var i = 0; i <; i++){
var msgid ;
if (json.list[i].waring == 3) {
msgid = '${res}/img/red.png';
}else if (json.list[i].waring == 2) {
msgid = '${res}/img/yellow.png';
}else {
msgid = '${res}/img/green.png';
}
var titlet = "";
if(json.list[i].readid == null){
titlet = "<td class='z-fontColorBlue'>"+ "<a href=\"javascript:diaban('"+json.list[i].taskid
+"','"+json.list[i].nodeid
+"','"+json.list[i].ywid
+"','"+json.list[i].lb
+"','"+json.list[i].departflag
+"','"+json.list[i].lastparentid
+"' ,'"+json.list[i].lastparent
+"' )\">"
+"<span>"+json.list[i].title
+"</span>"+"<img style=\"height:1.2em; width:1.6em;display:inline-block;border:none\" src=\"${res}/img/firstnew.gif\" />"+"</a></td>";
}else{
titlet = titlet = "<td class='z-fontColorBlue'>"+ "<a href=\"javascript:diaban('"+json.list[i].taskid
+"','"+json.list[i].nodeid
+"','"+json.list[i].ywid
+"','"+json.list[i].lb
+"','"+json.list[i].departflag
+"','"+json.list[i].lastparentid
+"' ,'"+json.list[i].lastparent
+"' )\">"
+json.list[i].title+"</a></td>";
}
var tr="<tr class='bg'><td>"+(i+1)+"</td>"
/*
+"<td>"+ json.list[i].lbstr +"</td>"
*/
+"<td>"+ json.list[i].code +"</td>"
+ titlet
+"<td>"+ json.list[i].acceptor +"</td>"
+"<td>"+ "<img class='light' src='" +msgid+ "'/></td>"
+"<td>"+ json.list[i].percents +"</td>";
var gzstr = "";
if(json.list[i].gz_id == null){
gzstr = "<td>"+"<button id='"+json.list[i].taskid+"' onclick=\"guanzhu('"+json.list[i].taskid+"');return false;\" >关注</button></td></tr>";
}else{
gzstr = "<td>"+"<button id='"+json.list[i].taskid+"' onclick=\"qxguanzhu('"+json.list[i].gz_id+"','"+json.list[i].taskid+"');return false;\">"+"<span style='color:red;'>★</span>已关注</buton>"+"</td>";
}
tr += gzstr;
$('#biaodan').append(tr);
}
}
});
}
java后台:
@RequestMapping("/first_Like")
@ResponseBody
public void ajax_generateCode(@RequestParam("code") String code,
@RequestParam("waring") String waring,
@RequestParam("title") String title) throws IOException {
Dmp dmp = this.getParamsAsDmp();
System.out.println(code+waring+title);
UserInfo user = getUserInfo();
String userid = user.getUserid();
dmp.put("userid", userid);
dmp.put("code", code);
dmp.put("waring",waring);
dmp.put("title", title);
List list = serv.select_first_lingdaorwcx(dmp);
System.out.println(list.size());
Dmp jsonmap=new BaseDmp();
if(list!=null && list.size()>0){
jsonmap.put("list", list);
}
String jsonstr=jsonmap.toJson();
this.writeResponse(jsonstr,"json");
}
ajax将json写到table中去的更多相关文章
- Ajax与json在前后端中的细节解惑
ajax请求JSON Thinkphp中对是否为Ajax的判断,在TP3.2开发手册中有这么一段:“需要注意的是,如果使用的是ThinkAjax或者自己写的Ajax类库的话,需要在表单里面添加一个隐藏 ...
- jQuery ajax 请求php遍历json数组到table中
html代码(test.html),js在html底部 <!DOCTYPE html> <html lang="en"> <head> < ...
- jQuery通过ajax请求php遍历json数组到table中的代码
html代码(test.html),js在html底部 具体代码如下所示: <!DOCTYPE html> <html lang="en"> <hea ...
- 前台序列化传过来的值,后台获取之后封装到map当中,让后在转化成json格式,最后在把json里面的参数里面的某一个值进行分割,最后在存到json格式的数据中去。
一,html脚本 <script type="text/javascript"> $(function() { $(".btn-submit").c ...
- C# web Api ajax发送json对象到action中
直接上代码: 1.Product实体
- MVC使用ajax取得JSon数据
为了在view中获取模型中的数据,用ajax异步模式读取数据,再用json返回的view中. 1.controller中: [HttpPost] public ActionResult GetAjax ...
- 。。。Ajax的回调函数function(data)中,data的返回类型。。。
今天在做项目的过程中,突然发现了一个有趣的问题,那就是我在Java服务器端写程序,String result = "0";然后通过out.println(result),将resu ...
- Tomcat 7 的七大新特性(更容易将Tomcat内嵌到应用去中去 )
Tomcat的7引入了许多新功能,并对现有功能进行了增强.很多文章列出了Tomcat 7的新功能,但大多数并没有详细解释它们,或指出它们的不足,或提供代码示例.本文将明确描述TOMCAT 7中七个最显 ...
- 通过Jquery中Ajax获取json文件数据
1. JSON(JavaScript Object Notation): javaScript对象表示法: 是存储和交换文本信息的语法,比xml更小,更快,更易解析. 2. JSON基本书写格式 : ...
随机推荐
- iOS设计模式笔记
设计模式 所谓设计模式,就是经过无数程序员的努力,在很多代码的基础上抽取出来的"模式" 一种设计模式,通常用来解决一种问题 MVC体系架构 也是一个设计模式,主要解决:界面(V), ...
- UEFI+GPT引导基础篇(一):什么是GPT,什么是UEFI?
其实关于UEFI的几篇文章很早就写下了,只是自己读了一遍感觉很不满意,就决定重写.目的是想用最简单直白的语言把内容写出来,让每个人都能轻松读懂.当然,如果你已经对这些内容有了很深的理解的话,这篇文章除 ...
- 1、B2BUA
链接1:proxy和B2BUA的区别和联系:http://www.cnblogs.com/gnuhpc/archive/2012/12/11/2813499.html 链接2:http://blog. ...
- vs2015 企业版 专业版 密钥
亲测可用 专业版:HMGNV-WCYXV-X7G9W-YCX63-B98R2企业版:HM6NR-QXX7C-DFW2Y-8B82K-WTYJV
- Hibernate部署问题总结
出现未知实体类(- org.hibernate.MappingException: Unknown entity),找不到cfg.xml包 (org.hibernate.internal.util.c ...
- 图片链接hover移动的解决方案分析
现实在网站中,我们经常看到有鼠标滑过某个图片,出现边框的效果.如下图:
- git和nginx安装
原始地址: https://www.zybuluo.com/freeethy/note/192109 git安装 设置git的username和email (注册gitlab的账号密码) $$ git ...
- NHibernate系列文章目录
第一章:NHibernate基础 NHibernate介绍 第一个NHibernate工程 简单的增删改查询 运行时监控 NHibernate配置 数据类型映射 Get/Load方法 NHiberna ...
- curl post方法
* [curl_post curl post方式请求接口] * @param [type] $url [接口的url] * @param [type] $data [传递的参数] * @return ...
- python---常见的数据队列
一.FIFO队列(先进先出) #!/usr/bin/env python # -*- coding:utf-8 -*- __author__ = 'zhoufeng' #FIFO队列 import q ...