0

我正在通过 ajax 调用发送一个 json 对象。
当我尝试打印 json 的值时,我得到了空值。

我究竟做错了什么?

小服务程序:

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


   response.setContentType("application/json");
   response.setCharacterEncoding("UTF-8");
   response.getWriter().write("[{\"PARENT\":\"2\",\"VAL\":\"X7280\"},{\"PARENT\":\"2\",\"VAL\":\"X8338\"}]");
}

javascript:

    function handleIt()      {              
        var url = "myservlet";
        var parameters = "method=method";
        http.open("POST", url, true);        

        http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        http.setRequestHeader("Content-length", parameters.length);
        http.setRequestHeader("Connection", "close");

        http.onreadystatechange = function() {
            if(http.readyState == 4) {                      
            var ddl3 = http.responseText;                           

            for(var key in ddl3){                   
                    var id = ddl3[key].PARENT;
                    var lbl = ddl3[key].VAL;

                    alert (lbl);

         }
      }
  }
    http.send(parameters);
} 
4

0 回答 0