2014-07-25 3 views
0

안녕하세요, jquery - servlet을 사용하여 parseerror ajax 호출하는 데 있습니다. 나는 잃어버린. 오, 어떻게 해야할지. dataType: 'json',을 잘 폐기하면 서블릿의 데이터가 유효한 json {"success":true,"SelectPartid":{"partidAll":"DA04321;"}}jquery ajax json parseerror 유효한 json 데이터

입니다. 하지만 나는 내가 때문에이 라인 2 시간을 낭비 믿지 못할 그래서, 아약스는

$("#select1").change(function() { 
    dataString = "Optionselected=" + $("#select1 option:selected").text(); 
    alert("dataString : " + dataString); 
    $.ajax({ 
     type: 'POST', 
     url: 'SelectAjx', 
     data: dataString, 
     dataType: 'json', 
     contentType: "application/json; charset=utf-8", 
     context: this, 
     success: function(data, textStatus, jqXHR) { 
      if (data.success) { 
       alert("SUCCESS!!"); 
       //alert("success" + data.SelectPartid.partidAll); 
      } 
     }, 
     error: function(jqXHR, exception) { 
      //alert('[jqXHR:' + jqXHR + '], [textStatus:' + textStatus + '], [thrownError:' + errorThrown + '])'); 
      if (jqXHR.status === 0) { 
       alert('Not connect.\n Verify Network.'); 
      } else if (jqXHR.status == 404) { 
       alert('Requested page not found. [404]'); 
      } else if (jqXHR.status == 500) { 
       alert('Internal Server Error [500].'); 
      } else if (exception === 'parsererror') { 
       alert('Requested JSON parse failed.'); 
      } else if (exception === 'timeout') { 
       alert('Time out error.'); 
      } else if (exception === 'abort') { 
       alert('Ajax request aborted.'); 
      } else { 
       alert('Uncaught Error.\n' + jqXHR.responseText); 
      } 
     } 
    }); 
}); 
+0

빠른 관찰. ''DA04321; "'은 이중 따옴표 안에';'* 틀림없이 * 있습니까? – CodingIntrigue

+0

응답 내용이 귀하가 우리에게 보여준 JSON과 비슷합니까? – idmean

+0

나는 http://jsonformatter.curiousconcept.com/에서 그것을 시험한다. 유효한 json 인 – user2300035

답변

0

application/json이 해결 조언을 해주십시오 코드를

if (data.success) { alert("SUCCESS!!"); //alert("success" + data.SelectPartid.partidAll); }

를 사용하지 못할. 아약스는 서블릿에 error..its를 발생시키지 않습니다.

라인에게 있습니다 난 그냥 DD는

response.setContentType("application/json;charset=UTF-8");

거기에 오류 swooshd의 away.thank 신

-copy로 변경 무엇

response.setContentType("text/html;charset=UTF-8");

마지막 코멘트에서이 사람이 유용 할 거라고 확신합니다.