2013-02-13 1 views
5

안녕하세요 저지에서 구현 된 Restful WS에 json 데이터를 게시하려고합니다. jquery-ajax를 통해 데이터를 게시하고 있습니다. HTTP Status-415가 지원되지 않는 미디어 유형을 가져 오는 이유는 무엇입니까? 고맙습니다. HTTP 상태 415 - JREERY에서 AJAX 호출에 대해 지원되지 않는 미디어 유형이 JERSEY로 구현 된 편안한 WS

//post method handler 
     @Path("/newentry") 
     public class NewEntry { 

      @POST 
      @Consumes(MediaType.APPLICATION_JSON) 
      public Response newEntry(String data) { 
        //doStuff 
     } 
    } 
    // ajax call 
     $.ajax({ 
       url: "http://localhost:8080/FirstRestWebService/rest/newentry", 
       type: "post", 
       data: formToJSON(), 
       dataType : "json", 
       success: function(data){ 
       alert("success"); 
        }, 
       error:function(jqXHR, textStatus, errorThrown) { 
        alert("failure"); 
        } 
      }); 

     function formToJSON() { 
       return JSON.stringify({ 
        "name": $("input#emp_name").val(), 
        ... 
        "username": $('input#username').val(), 
        "password": $('input#password').val() 
        }); 

Click here for screenshot of firebug description Click here for screenshot of firebug description


나는 뉴저지 클라이언트
에 의해 성공적으로 WS를 테스트 할 수 있었다. 위의 AJAX 호출에서 잘못된 점은 무엇입니까? 고맙습니다.

contentType: "application/json" 

답변

17

는 콘텐츠 유형을 설정해야 호출합니다. pom.xml에 다음 종속성을 추가하십시오.

<dependency> 
    <groupId>com.owlike</groupId> 
    <artifactId>genson</artifactId> 
    <version>0.98</version> 
</dependency> 
+0

대단히 고마워. – mik

1

당신은 JSON 종속성을 선언해야합니다 : 당신의 AJAX에서

관련 문제