title: How to get json response from server in JSON format using jquery ajax
body: <p>I am getting parse Error</p>
  
  <p>Ajax </p>
  
  <pre><code>$.ajax({
                      type: "POST",
                      url: "getStagingImrReport.do",
                      data: dataString,
                      dataType: "JSON", 
                      //if received a response from the server
                      success: function( data, textStatus, jqXHR) {  //our country code was correct so we have some information to display  
                          alert(data);
                        //$("#ajaxResponse").html("&lt;div&gt;&lt;b&gt;Country code in Invalid!&lt;/b&gt;&lt;/div&gt;"); 
                      }, 
                      //If there was no resonse from the server
                      error: function(jqXHR, textStatus, errorThrown){
                          alert("Something really bad happened " + textStatus);
                            //$("#ajaxResponse").html(jqXHR.responseText);
                      }, 
                      //capture the request before it was sent to server
                      beforeSend: function(jqXHR, settings){
                          //adding some Dummy data to the request
                          settings.data += "&amp;dummyData=whatever";
                          //disable the button until we get the response
                          $('#myButton').attr("disabled", true);
                      }, 
                      //this is called after the response or error functions are finsihed
                      //so that we can take some action
                      complete: function(jqXHR, textStatus){
                          //enable the button 
                          $('#myButton').attr("disabled", false);
                      } 
                  }); 
  </code></pre>
  
  <p><strong>controller</strong> </p>
  
  <pre><code>public void getStagingImrReport(HttpServletRequest request,
              HttpServletResponse response) throws Exception {
          try {
              // String policyType = request.getParameter("policyType");
              List&lt;String&gt; drop = new ArrayList&lt;String&gt;();
              response.setContentType("application/json");
              response.setHeader("Cache-Control", "no-cache");
              response.setHeader("Pragma", "no-cache");
              final ILoadMgr iLoadMgrRef = (ILoadMgr) getContext().getBean(
                      IConstants.LOAD); 
              List&lt;PTypeVO&gt; listVO = iLoadMgrRef
                      .getPolicyTypes(IConstants.MFFILTER);
              for (PTypeVOpolicy : listVO) {
                  drop.add(policy.getPolicyTypeName()); 
              }
              JSONObject jsonObject=new JSONObject();
              jsonObject.put("jsonVal", drop);
              PrintWriter out = response.getWriter(); 
              System.out.println(" XXXX--------"+drop);
  
              out.println(drop); 
              out.flush();
          } catch (Exception exp) {
              Logging.error(
                      "[LoadController.getpolTypesAjaxDropdown] Exception occured ",
                      exp);
          }
      }
  </code></pre>
  
  <h2>Output on console for sysOut</h2>
  
  <pre><code> //----XXXX--------[CHIP, County Health Program, Disability, Discount Card, Imputed, Indian Tribe, Mail Order, Medicaid MCO, No Coverage, Other, Rehabilitation, State]
  </code></pre>
  
  <p>and Jquery alert message shows:</p>
  
  <pre><code>"something really bad happened parse error"
  </code></pre>