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基本书写格式 : ...
随机推荐
- 尚学堂Spring视频教程(六):AOP Annotation
此处省略N个字.... 直接看下面 推荐链接: Spring Aop实例之AspectJ注解配置
- PowerDesigner设计时表显示注释选项
PowerDesigner设计时表显示注释选项:选定编辑的表,右键- >Properties- >Columns- >Customize Columns and Filter(或直接 ...
- 1不等于1?numeric、decimal、float 和 real 数据类型的区别
大家有没有在SQL中遇见1不等于1(1<>1)的情形!?下面会有一个例子演示这个情形. 先简单介绍一下标题中的四种数值数据类型. 在T-SQL中,numeric和decimal是精确数值数 ...
- git&sourcetree安装及在IntelliIJ下拉取项目基础使用
be careful: 1)git版本与Sourcetree版本最好一致 ,不能git为2.5,sourcetree为1.8 2)先安装git再安装Sourcetree 3)拥有git和sourcet ...
- C/C++程序员应聘试题剖析(转载)
转载自:http://www.cnitblog.com/zouzheng/articles/21856.html 1.引言 本文的写作目的并不在于提供C/C++程序员求职面试指导,而旨在从技术上分析面 ...
- virt-manager管理整个云平台的instances
http://people.redhat.com/~rjones/virt-top/faq.html
- 从request获取远程IP地址
public static String getIpAddr(HttpServletRequest request) { String ip = request.getHeader("X-F ...
- MaxScript重启3dsMax的重新思考
前天看到一位大神写用MaxScript实现重启3dsMax的方法,用的是.net临时编译一个exe出来,然后用这个新的进程来关闭并开启新的max.感觉这种思路不错,或许可以用在别的地方.不过谈及max ...
- Unity IOC简单认知
看了不少IOC的文章.简单概念梳理下. 1.依赖,依赖倒置,控制反转(IOC),依赖注入 解释是仿照http://www.cnblogs.com/qqlin/archive/2012/10/09/27 ...
- Java位运算经典实例
一 源码.反码.补码 正数的源码.反码.补码相同,例如5: 5的源码:101 5的反码:101 5的补码:101 负数的源码.反码.补 ...