jquery & json

1:Action

      ServletOutputStream out = response.getOutputStream();//用这个传到jsp的中文 不会出现乱码
      JSONArray jsonArray = new JSONArray() ;
      JSONObject json;
      response.setContentType("text/html; charset=UTF-8");
      response.setCharacterEncoding("UTF-8");

 

        json = new JSONObject();
        json.put("id", addresslist2.getId()+"");
        json.put("name",addresslist2.getName()+"");
        json.put("email",addresslist2.getEmail()+"");
        json.put("firstName",addresslist2.getFirstName()+"");
        json.put("lastName",addresslist2.getLastName()+"");
        json.put("validity",addresslist2.getValidity()+"");
        json.put("status",addresslist2.getStatus()+"");
        jsonArray.add(json);

 

      out.print(jsonArray.toString());
      out.flush();     
      out.close();

 

2:jsp

(1):  $.getJSON //get  参数跟在url后面
     (
         "url",
           function(json)
         {
           );

 

(2): //提交form 表单 form 的id 为 form1

var data = $("#form1").serialize();
    $.ajax({
      url: "url",
      type:"post",         
      data: data,
      dataType:"json",
      success:function(json)
    {

    }
    });

 

你可能感兴趣的:(html,jquery,Ajax,json,jsp)