Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Async jquery invocation to rest service

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to invoke an asynchronous restful web service from jquery. The problem is that the HTTP client does not refresh when receiving the result, I have to refresh the browser manually. This is the jquery code I am using:

Any help is appreciated!!
 
Sheriff
Posts: 67583
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

G Peruana wrote:The problem is that the HTTP client does not refresh when receiving the result, I have to refresh the browser manually.


Yeah, that's how Ajax works. The whole point of Ajax is to contact the server without the need to refresh the entire page. What are you expecting to actually happen?

And please post good code. The code you posted is too full of errors to work.
 
G Peruana
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shouldnt it get updated without the need to refresh?

The code might have some minor error because I tried to delete all comments and not relevant code.
 
Bear Bibeault
Sheriff
Posts: 67583
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

G Peruana wrote:Shouldnt it get updated without the need to refresh?


What is "it"? If you are asking about the HTML fragment that will be inserted in the DOM, then yes, no need to refresh. but you are not being at all clear about what you are trying to do, and what's going awry.

The code might have some minor error because I tried to delete all comments and not relevant code.


That's not going to cut it. When that happens, everyone spends time looking at the bogus errors instead of the real problem. When posting code, please be sure to post an SSCCE (⇐ that's a link) that demonstrates the problem.
 
G Peruana
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me give you the complete code and further explanation:

I am trying to fulfill an invocation from jquery to an Asynchronous service (just following the asynchronous example fro jersey tutorial). I give below the two examples I tried (simple one and with callvback) and explain the results an errors. Any help with any of the examples is welcomed, I am just trying to guess what I am doing wrong.

First example:
In the service side I have the following code:



In the client side I have the following one



If I execute the html web I get the 'asy' alert (therefore asyncGet is being invoked) but I do not get any result in data.
If I add the empty return that is now commented in asyncGet (I read it in some forums) , I get the following error "SEVERE: Error while closing the output stream in order to commit response.
java.lang.NullPointerException"

If I test the callback example:


Using the same client code, what I get is
1) Currently alert asy is shown and in the server console "throwable" is shown; therefore the asyncGetWithCallback is being invoked. But still I do not get the data in the client.
2) From time to time if I test in a different browser window I get only the data (WORKING)

Any help is really appreciated.
 
Bear Bibeault
Sheriff
Posts: 67583
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You haven't set the dataType property for the Ajax call.
 
G Peruana
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for you reply. It does not seem to be problem. if you include "dataType: "text",", which is the type received, I still get the same result.
 
Bear Bibeault
Sheriff
Posts: 67583
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are getting an NPE on the server, then you need to isolate which reference is null, and backtrace to find out why it is null.
 
G Peruana
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But how do I manage to locate the npe?
 
Bear Bibeault
Sheriff
Posts: 67583
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you inspected the stack trace?
 
G Peruana
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, and I am debugging with chrome debugger.

The thing is, when no error is launched, the data returned is simply empty. This is why (I guess) it is an async method and the resume method is not reaching the way back. Something in the way I am implementing the callback is wrong. I looked over other forums and found more people having trouble for making this jersey example work and no solutions yet.


When error is launched (ONLY SOMETIMES) I get the following in Eclipse console


Thanks for the replies!!
 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was not coming to this thread on purpose. Just by accident.
So this is JAX-rs 2.0 and new to me. But there is a JAX-RS 2.0 client api.

Since you have JAX-rs 2.0 on server. Why don't you try to test the use case with JAX-rs 2.o client api.
This is to ensure you get what you expected. Java-to-java end-to-end. Once you're sure the server code is OK.

Then test the server code with various client code which is jquery in your case or any language.
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic