0

这是java代码;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

      Map<String,Object> hsssmap= new HashMap<String,Object>();
      hsssmap.put("a","true");
      hsssmap.put("b","true");
      write(response,hsssmap);

}
private void write(HttpServletResponse response, Map<String,Object> hsssmap) throws IOException {
         response.setContentType("application/json");       
         response.setCharacterEncoding("UTF-8");
         Gson gson = new Gson();
         String json = gson.toJson(hsssmap);
         response.getWriter().write(json);

}   

这是js代码;

$(document).ready(function(){   
 $.ajax({
url: 'uri',
    type: 'POST',
dataType: 'json',
data: data,

success: function(data){
     $.each (data, function (key,value) {

        alert(key+" "+value);
     });
 },
 error: function (e) {
     alert("error : " + e);
     }

});

return false;
});

成功事件不起作用。如何解决?

4

2 回答 2

0

尝试检查页面是否返回一些值...

尝试添加警报成功以检查它..

于 2013-09-18T21:13:12.433 回答
0

尝试以下

$.post( "uri", function(data) {
alert( "success" + data.a + data.b );
})

如果这会返回您的数据,那么您的服务器端 servlet 正在工作

于 2013-09-18T21:27:13.517 回答