查询条件:

<table style="width: 100%;border-collapse: collapse;" >
<tr>
<th style="width: 15%;">分&nbsp;&nbsp;&nbsp;类:</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=''>全部&nbsp;
<input type="radio" name="z-status" id="z-normal" value='1'>正常&nbsp;
<input type="radio" name="z-status" id="z-pro-overdue" value='2'>可能超期&nbsp;
<input type="radio" name="z-status" id="z-overdue" value='3'>超期&nbsp;
</td>
</tr>
<tr>
<th>名&nbsp;&nbsp;&nbsp;称:</th>
<td colspan="3">
<input id="serchname" class="zxui-textbox" style="width: 80%;">&nbsp;&nbsp;
<a href="javascript:search()" class="zxui-linkbutton" data-options="iconCls:'icon-search'" style="width:80px;line-height:22px;">筛&nbsp;选</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中去的更多相关文章

  1. Ajax与json在前后端中的细节解惑

    ajax请求JSON Thinkphp中对是否为Ajax的判断,在TP3.2开发手册中有这么一段:“需要注意的是,如果使用的是ThinkAjax或者自己写的Ajax类库的话,需要在表单里面添加一个隐藏 ...

  2. jQuery ajax 请求php遍历json数组到table中

    html代码(test.html),js在html底部 <!DOCTYPE html> <html lang="en"> <head> < ...

  3. jQuery通过ajax请求php遍历json数组到table中的代码

    html代码(test.html),js在html底部 具体代码如下所示: <!DOCTYPE html> <html lang="en"> <hea ...

  4. 前台序列化传过来的值,后台获取之后封装到map当中,让后在转化成json格式,最后在把json里面的参数里面的某一个值进行分割,最后在存到json格式的数据中去。

    一,html脚本 <script type="text/javascript"> $(function() { $(".btn-submit").c ...

  5. C# web Api ajax发送json对象到action中

    直接上代码: 1.Product实体

  6. MVC使用ajax取得JSon数据

    为了在view中获取模型中的数据,用ajax异步模式读取数据,再用json返回的view中. 1.controller中: [HttpPost] public ActionResult GetAjax ...

  7. 。。。Ajax的回调函数function(data)中,data的返回类型。。。

    今天在做项目的过程中,突然发现了一个有趣的问题,那就是我在Java服务器端写程序,String result = "0";然后通过out.println(result),将resu ...

  8. Tomcat 7 的七大新特性(更容易将Tomcat内嵌到应用去中去 )

    Tomcat的7引入了许多新功能,并对现有功能进行了增强.很多文章列出了Tomcat 7的新功能,但大多数并没有详细解释它们,或指出它们的不足,或提供代码示例.本文将明确描述TOMCAT 7中七个最显 ...

  9. 通过Jquery中Ajax获取json文件数据

    1. JSON(JavaScript Object Notation): javaScript对象表示法: 是存储和交换文本信息的语法,比xml更小,更快,更易解析. 2. JSON基本书写格式 : ...

随机推荐

  1. The novaclient Python API

    The novaclient Python API Usage First create a client instance with your credentials: >>> f ...

  2. JSP+Servlet中使用jspsmartupload.jar进行图片上传下载

    JSP+Servlet中使用cos.jar进行图片上传 upload.jsp <form action="FileServlet" method="post&quo ...

  3. Nopcommerce 二次开发1 基础

    1  Doamin    酒店 namespace Nop.Core.Domain.Hotels { /// <summary> /// 酒店 /// </summary> p ...

  4. 织梦系统“当前位置”{dede:field.position}的修改方法

    dedecms中修改当前位置{dede:field.position},就是只要首页>一级栏目>二级栏目这样.找到include/typelink.class.php,找到这个文件里的这个 ...

  5. java笔试面试二

    http://www.cnblogs.com/lanxuezaipiao/p/3371224.html

  6. 关于Java static 的学习心得

    static,大家都很熟悉.但是要说真的懂,那就很少了.(当然我也不是很懂,但不妨碍学习吗.) 首先,我认为static修饰的成员就是属于类本身的成员.如果你加了一个static修饰符,好吧,那就相当 ...

  7. MES系统学习

    MES系统是当今制造型企业信息化的热点,而统一建模语言UML是面向对象建模的标准语言,在软件工程发挥着重要作用.MES系统如何进行UML建模呢,今天和大家重点讨论一下MES系统的UML建模方法,请看本 ...

  8. js学习笔记(一)

    js 有5中原始类型:number. string. boolean. null.undefined js 有6中类型: 5中原始类型 在加上1中Object类型 typeof null === 'o ...

  9. JS function document.onclick(){}报错Syntax error on token "function", delete this token

    JS function document.onclick(){}报错Syntax error on token "function", delete this token func ...

  10. C语言中两种方式表示时间日期值time_t和struct tm类型的相互转换

    使用gmtime函数或localtime函数将time_t类型的时间日期转换为structtm类型: 使用time函数返回的是一个long值,该值对用户的意义不大,一般不能根据其值确定具体的年.月.日 ...