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基本书写格式 : ...
随机推荐
- mvc ajax csrf
http://www.cnblogs.com/zhyp/p/5556980.html http://www.asp.net/web-api/overview/security/preventing-c ...
- Java多线程之并发协作生产者消费者设计模式
两个线程一个生产者个一个消费者 需求情景 两个线程,一个负责生产,一个负责消费,生产者生产一个,消费者消费一个 涉及问题 同步问题:如何保证同一资源被多个线程并发访问时的完整性.常用的同步方法是采用标 ...
- SpringMVC 自动封装枚举类的方法
springmvc默认无法自动封装枚举类,解决方法如下: 1.枚举类 public enum GoodsPromoteEnum { /** * 0 精品 */ fine("精品", ...
- 如何使用PL/SQL进行远程数据库连接
1.先找到Oracle数据库的安装地址然后找到network->ADMIN->tnsnames.ora文件 2.添加下面文件到tnsnames.ora文件中去,红色部分是需要修改的部分 ...
- C/C++二维数组分配内存
//C++方式 double **Q=new double*[row]; //初始化Q矩阵 for(int i=0;i<row;++i) Q[i]=new double[POS_NUM]( ...
- Winmail.dat(TNEF) issue on outlook
http://www.dwheeler.com/essays/microsoft-outlook-tnef.html
- vs快捷键汇总
1.相关查找快捷键 Ctrl+F: 查找 Ctrl+Shift+F: 在文件中查找 F3: 查找下一个 Shift+F3: 查找上一个 Ctrl+H: 替换 Ctrl+Shift+H: 在文件中替换 ...
- java知识点
一.面向对象的五大基本原则: 1.单一职责原则(Single-Resposibility Principle):一个类,最好只做一件事,只有一个引起它的变化.单一职责原则可以看做是低耦合.高内聚在面向 ...
- hibernate复合主键
需要用到实体类Role的主键和Menu的主键结合起来作为实体类RoleMenu的主键,那么通过Hibernate具体实现如下: RoleMenu实体类:(注意该实体类需要实现Serializable接 ...
- .NET 工具类ObjectDumper 打印对象
// Comes from the LINQ samples provided by Microsoft //Copyright (C) Microsoft Corporation. All righ ...