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' }";
        }

}
有帮助吗?

解决方案 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.

其他提示

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);
          }
    });
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top