user3469203
user3469203

Reputation: 547

http 500 on ajax call in jquery

I got this ajax call :

var request = $.ajax({
    type : "GET",
    url : "/services/ged/download?pIdDocument=" + idDocument
});

idDocumenthas this kind of value : {3F15D23C-1E9F-678B-B865-654E5866959F}

Here's le server side rest service :

@Path("/ged")
@RequestScoped
public class GedRest {

    @GET
    @Path("/download/{pIdDocument}")
    @Produces("application/pdf")
    public Response downloadPdfFile(@Context HttpServletRequest pRequest, @PathParam("pIdDocument") String pIdDocument) throws AInternalException {
        // Get a pdf document
    }
}

I got a http 500 on the browser, and here is the server side log :

com.sun.jersey.api.NotFoundException: null for uri: http://localhost:7003/services/ged/download?pIdDocument=%7B0F90D68C-3E9F-472B-B8F5-658E5816919F%7D

I tried to replace - by %2D that's the same:

com.sun.jersey.api.NotFoundException: null for uri: http://localhost:7003/services/ged/download?pIdDocument=%7B0F90D68C%2D3E9F%2D472B%2DB8F5%2D658E5816919F%7D

Any idea?

Upvotes: 0

Views: 62

Answers (2)

David Jones
David Jones

Reputation: 4305

Looks like when you are defining the route you are assigning the pIdDocument to be part of the URI and not as a GET variable.

Try this as the url in your AJAX call:

"/services/ged/download/" + idDocument

Upvotes: 1

Shrinivas Shukla
Shrinivas Shukla

Reputation: 4453

What you need to do is

var request = $.ajax({
    type : "GET",
    url : "services/ged/download?pIdDocument=" + idDocument
});

Notice that I removed the starting / from the URl.

When a URL starts from /, it is considered from the root directory, which is NOT desired.

Remove the starting / from the URL and it will act as a relative URL.

Upvotes: 1

Related Questions