Domanda

I have problem in callback function in jquery.

lets start from the beginning. My restful web service url is this

http://localhost :35055/new/webresources/generic/1

and it will return

{'name':'get', 'age':58}

and my jquery to interact with this web service is

$(document).ready(function() {
    $.ajax({
        dataType: "json",
        url: '/webresources/generic/1',
        type: 'GET',
        data: ' ',
        success: function() {
            alert('PUT completed');
        }
    });
});

which is linked in the jsp page

http://localhost:35055/new/tool.jsp 

there is no alert message. Please suggest me a way and also debug this code please.

this is the restful webservice

    @GET
    @Produces("application/json")
    public String getJson( @PathParam("venki") int empno ) {
        if(empno==1)
        {
      return "{'name':'get', 'age':'58' }";
        }
        return "{'name':'error', 'age':'58' }";
        }

}
È stato utile?

Soluzione 2

Retry by correcting url setting value to '/new/webresources/generic/1' like this:

$.ajax({
  url: '/new/webresources/generic/1', 
  success: function() { alert('PUT completed'); }
});

According to your updated Java code of web service implementation, you should refer to answer of How correctly produce JSON by RESTful web service to find the correct java code.

Altri suggerimenti

You can expose the error through the error property of the $.ajax call if you aren't familiar with using Fiddler or the built in browser tools to inspect network traffic.

$(document).ready(function() {
    $.ajax({
        dataType: "json",
        url: '/new/webresources/generic/1',
        type: 'GET',
        data: ' ',
        success: function() {
            alert('PUT completed');
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
          }
    });
});
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top