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基本书写格式 : ...
随机推荐
- python 2day
一 优化 username='alex' password=‘alex123’ 可以写成 username,password =‘alex’,'alex123' 二.再次优化 for i in ran ...
- 解决window2012 IIS8 配置的网站无法下载exe文件的问题
window2012 IIS8 配置网站下载exe文件.解决window2012 IIS8 配置的网站无法下载exe文件的问题 配置好网站后,无法下载网站上的exe文件,zip文件确可以下载的.右键点 ...
- JavaScript能干什么?
真的是长见识了,JavaScript居然能做除了WEB界面外运行于任何平台的APP,而且可以做服务器端,还有天理和王法吗?JavaScript到底有多神奇,要不要重新上路,老程序员何去何从,自然要先网 ...
- Java Socket编程
Java最初是作为网络编程语言出现的,其对网络提供了高度的支持,使得客户端和服务器的沟通变成了现实,而在网络编程中,使用最多的就是Socket.像大家熟悉的QQ.MSN都使用了Socket相关的技术. ...
- oozie调用shell
<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agree ...
- Hyperledge 开发环境配置常见问题
一,安装工具 VBOX vagrant vagrant proxy golang 二,下载源代码 hyperledge gotools 三. 1. ==> default: package g ...
- 【原创】loadrunner12.53 录制脚本时 打不开网页或者打开网页慢?
问题描述: 之前刚装12.5版本时候,用 WebTours测试过,应用程序选择自己本地IE浏览器.exe程序,输入url地址就可以成功录制了 . 但是由于公司网络配置环境改变了(猜测),现 ...
- 这些年正Android - 身在他乡
“从不敢想到想去做到,做到我想的,事实证明我并不像他们想象的那样脆弱.我只是需要一盏灯,一架钢琴,一支麦克风.曾经想象过做一名医生救死扶伤,也曾想过做律师,做记者,做奥运冠军,但是都没有结果.因为我最 ...
- wordpress stratus模板使用 产品显示问题
产品不显示,只显示展示产品代码. 1.研究原站demo,思考产品展示调用自woocommerce. 2.查看woocommerce文档,更新展示代码. 3.修改后产品出现,但是多余的关联推荐也展示出来 ...
- 字符串怎么换行 || 字符串中使用单引号时应该怎么写 || 保留两位小数 || 数字0在if中的意思是false || 什么情况下会会报undefined || null和undefined的区别 ||
换行的字符串 "This string\nhas two lines" 字符串中使用单引号时应该怎么写 'You\'re right, it can\'t be a quote' ...