注册 登录
编程论坛 jQuery论坛

在使用 jquery ajax json jsp 处理数据时出错

z68752553 发布于 2010-12-08 11:04, 4915 次点击
  没有成功答应出page的值,请问该怎么修改才能让程序正确执行。
------------------------index.jsp页面
    <script src="JS/JQuery.js" type="text/javascript"></script>
    <script type="text/javascript">
   
  function _data(){
   $.ajax({
   
   url: "index2.jsp",
   data: {page:2},
   dataType: "json",
   contentType: "application/json;charset=utf-8",
   type: "get",
   success: function (data,textStatus){
   alert(data.page);
   }
});
}
</script>
  </head>
 
  <body>
    <input type="button" id="ajaxs" value="Ajax" onclick="_data()"/>
  </body>

------------------------inde2.jsp页面

  <body>
     <%
             response.setCharacterEncoding("gb2312");
            request.setCharacterEncoding("gb2312");
            String page2=request.getParameter("page");
             response.setContentType("application/json;charset=utf-8");
            PrintWriter out2= response.getWriter();
             JSONArray jsonArray = new JSONArray();
            JSONObject json = new JSONObject();
            
            json.put("page",page2);
            out2.write(json.toString());
            
      %>
  </body>
1 回复
#2
hugeannex2010-12-11 13:52
表面看代码是没错误,但谁知道你这JSONObject里又是怎么写的?
1