0

jquery を介して REST ベースの API (JAX-RS/Jersey ベースの API) に get リクエストを送信しようとしています。ログで見たように、リクエストは API に正常に到達し、firebug では 200 の OK 応答が見られました

以下は私のjqueryベースのクライアントです

$(document).ready(function(){
    $("button").click(function(){
        $.ajax({
            type: 'GET',
            url: 'http://mtnlp.com:8080/restdemo/resources/employee/1',
            dataType: "json",
            success: function(data){
                alert("success");
            },
            error: function(xhr){
               alert("error"+xhr.status);
            }
        });
    });
});

しかし、xhr.status は 0 です。

私のリソースは

@GET
@Produces(MediaType.APPLICATION_JSON)
public String getJson( @PathParam("empno") int empno) {  
    JSONObject jObject = new JSONObject();
    System.out.println("someone calls me");
     switch(empno) {
        case 1 :
          jObject.put("name", "George Koch");
          jObject.put("age", "58");
          break;
      case 2:
          jObject.put("name", "Peter");
          jObject.put("age", "50");
          break;
      default:
          jObject.put("name", "Unknown");
          jObject.put("age", "-1");


  } // end of switch

  return jObject.toString();
} 

ジャージーベースのクライアントを使用すると、正常に動作します。しかし、jquery ベースのクライアントでは、上記の問題に直面しています。

HTTP get リクエストのリクエスト ヘッダーとレスポンス ヘッダーの下を参照してください。

応答ヘッダー

Content-Type: application/json
Date: Tue, 04 Jun 2013 06:38:12 GMT
Server: Apache-Coyote/1.1
Transfer-Encoding: chunked

リクエスト ヘッダー

Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate Accept-Language  en-US,en;q=0.5
Host: localhost:8080
Origin: null
User-Agent: Mozilla/5.0 (Windows NT5.1; rv:19.0) Gecko/20100101 Firefox/19.0
4

0 に答える 0