ajax&&json

<!--回车进入页面-->
function enter(){
if(window.event.keyCode == 13)
{ var workcode = $F('workcode');
var url = '/HrmResourceAdd1.jsp';
var pars = 'workcode=' + workcode;
var myAjax = new Ajax.Request(url, {method: 'get', parameters: pars, onComplete: showResponse});

}

}
function showResponse(originalRequest) {
var resText = originalRequest.responseText.evalJSON();
$('lastname').value = resText.personInfo[0].lastname;
$('telephone').value = resText.personInfo[0].telephone;
$('mobile').value = resText.personInfo[0].mobile;

}
HrmResourceAdd1.jsp

<%@ page language="java" pageEncoding="GB2312"%>
<%@page import="org.json.JSONArray"%>
<%@page import="org.json.JSONObject"%>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page"/>
<%
String workcode = request.getParameter("workcode");
//根据workcode取数据库信息 得到结果集

JSONArray jsonList = new JSONArray();//
JSONObject obj = new JSONObject();//
String sql="select * from employee se where se.badge='"+workcode+"'";
RecordSet.executeSql(sql);
//循环
while(RecordSet.next()){
obj.put("workcode",RecordSet.getString("badge"));
obj.put("lastname",RecordSet.getString("name"));
obj.put("telephone",RecordSet.getString("OFFICEPHONE"));
obj.put("mobile",RecordSet.getString("mobile"));
obj.put("fax",RecordSet.getString("telephone"));
obj.put("email",RecordSet.getString("email"));

jsonList.put(obj);//
}
//循环结束


JSONObject json = new JSONObject();
json.put("personInfo", jsonList);
//response.setHeader("X-JSON", json.toString());
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");// 清楚缓存
response.getWriter().print(json.toString());
%>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值