首页 > 代码库 > Ajax && json(原始)

Ajax && json(原始)

function findSend() {
        $.ajax({
//            async: false,
//            cache: true,
            type: "POST",
            url: "InMessageServlet?action=findSend",
            data: $(‘#receiveForm‘).serialize(),// 你的formid
            dataType: ‘json‘,
//            error: function(request) {

//            },
            success: function (data) {
//                alert(data.success);
//            window.location.href = "http://www.mamicode.com/InMessageServlet?action=one";

            }
        });
    };
public void findSend(HttpServletRequest request, HttpServletResponse response) throws Exception {

List<InMessage> list = new ArrayList<InMessage>();
InMessage im = new InMessage();
。。。。。。
list.add(im);
JSONArray json = new JSONArray();
for (InMessage a : list) {
JSONObject jo = new JSONObject();
jo.put("mainMessage", a.getMainMessage());
jo.put("sendUserName", a.getSendUserName());
json.put(jo);
}
request.setCharacterEncoding("utf-8");
response.setContentType("text/json");
PrintWriter out = response.getWriter();

out.print(json);
out.flush();
out.close();
}



  

Ajax && json(原始)