Bonjour,

j’utilise jquery ajax pour appeler un web service de type get codé en java.

L'appel est bien passé (satuts= 200, textStatus= 4), mais il me met undefined comme réponse de la fonction success.

Pouvez vous m'aider svp et me dire où est l'erreur?

Merci.

Mon web serveur:
Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
@GET
    @Path("/term/{term}")
    @Produces({MediaType.APPLICATION_JSON})
    public Response termQuery(@PathParam("term") String term ) {//, @PathParam("index") String index, @PathParam("type") String type) {    
        try {
 
            log.debug("searsh");
            //log.debug("index = " + index);
           // log.debug("type = " + type);
            log.debug("term = " + term);
         List<String> results = multiTypeSearchService.getTermQueryData(term);
            if (null == results) {
                return Response.status(Status.BAD_REQUEST).entity("arg obligatoire").build();
                }
         //String  suggestions = String.join(",", results);
            String json = new Gson().toJson(results);
            return Response.ok(json).build();
        } catch(Exception e) {
               return tmExceptionMapper.toResponse(new TmException(Code.TECHNICAL_ERROR, e.getMessage()));
           }
    }

jquery code:
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="fr">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
    <h1>Recupération de données ...!</h1>
    <textarea id ="input_search" class="form-control custom-control" rows="10"></textarea> 
    <textarea id = "output" class="Output" rows="10"></textarea>
    <button type="button" onclick="readfile()">Search</button>
<script>
         
      var showoutput = $('#output');   
      var Url_newtm = 'http://localhost:8080/newtm/term/';
      function readfile(){
        var text_search = $('#input_search').val();
        $.ajax({
            //headers: {'Access-Control-Allow-Methods': 'GET'},
            contentType: "application/json; charset=UTF-8",
            type:'GET',
            data: {},
            url:Url_newtm+text_search,
            dataType: "script",
            async: false,
             
            success: function(data, jqXHR, textStatus){
                //alert(data);
                //$('#output').html(result);
                console.log(data);
              },
              error: function(jqXHR, textStatus, errorThrown){
                console.log("error");
                console.log(errorThrown)
                console.log(textStatus)
                console.log(jqXHR);
              },
          });
      }
</script>
</body>
</html>

Nom : 1.PNG
Affichages : 7598
Taille : 49,3 Ko