2012-05-20 2 views
0

JAX-RS를 사용하여 Restufl 웹 응용 프로그램을 작성하고 있습니다. json 객체를 사용하는 post 메소드로 webservice를 호출 할 때 문제가 있습니다. "NetworkError : :이 오류 얻을jquery를 사용하여 JAX-RS를 호출합니다.

var data={'adressCl':'myAdress','emailCl':'[email protected]'}; 
$.ajax({ 
"type":"post", 
"dataType":"json", 
"data":data, 
"url":"http://localhost:9080/FournisseurWeb/jaxrs/clients/client", 
"success":function(res){ 
console.log(res); 
} 
});/* 
$.post("http://localhost:9080/FournisseurWeb/jaxrs/clients/client",data,function(res){ 
console.log(res); 
});*/ 

: 나는이 방법 jQuery로

@POST 
@Path("/client") 
@Consumes(MediaType.APPLICATION_JSON) 
public Response showClient(Client c){ 
    String name = c.getAdresseCl() + ""+ c.getEmailCl(); 
    ResponseBuilder builder = Response.ok(name); 
    builder.header("Access-Control-Allow-Origin", "*"); 
    builder.header("Access-Control-Max-Age", "3600"); 
    builder.header("Access-Control-Allow-Methods", "GET"); 
    builder.header(
      "Access-Control-Allow-Headers", 
      "X-Requested-With,Host,User-Agent,Accept,Accept-Language,Accept-Encoding,Accept-Charset,Keep-Alive,Connection,Referer,Origin"); 
    return builder.build(); 
} 

클라이언트 호출입니다 JQuery와
를 사용하여 웹 서비스를 호출해야합니다! 이 도움을 주시기 바랍니다 415 지원되지 않는 미디어 유형 및 미리 사전에

+1

운영자는 http://stackoverflow.com/questions/10679060/ajax-call-to-jax-rs-with-jquery-issue와 정확히 일치합니다. 삭제 해주세요. – n4rzul

답변

0

에서 http://api.jquery.com/jQuery.ajax/contentType 필드 설명 그것은 .ajax()는 기본적으로 응용 프로그램/x-www-fo rm-urlencoded, json이 아니기 때문에 제대로 설정해야합니다. application/json

"type": "POST"는 항상 "type"을 사용합니다. 그것이 문제이다.

관련 문제