• 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
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

ajax call and dynamic content refreshing

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I heard jQuery (or dojo) can make ajax call (xhr) to server to get json data and display them on the page.
But this thing can be done using jsp too (jsp cna get java bean and render it on page). What's the difference and advantage of jquery or dojo call ?

Another question --- when the data on server side changes at real time, does the page written in jquery or dojo ajax call get them instantly without
having to load the entire page ? if yes, how ? how can the ajax call keep happening all the time by itself ?

Please give some conceptual clarification help. Thanks !
 
Sheriff
Posts: 67590
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

ben oliver wrote:I heard jQuery (or dojo) can make ajax call (xhr) to server to get json data and display them on the page.


JSON is data, so it'd be unlikely to be directly displayed in a page. Rather, elements can be created using the JSON data. Or, commonly, HTML fragments are returned which are directly injected into the DOM.

But this thing can be done using jsp too (jsp cna get java bean and render it on page).


JSP works on the server prior to the page being sent to the browser. It cannot react to user events or change just part of a page¹.

when the data on server side changes at real time, does the page written in jquery or dojo ajax call get them instantly without
having to load the entire page ?


Well, I don't know if I'd call it "instantly", but yes, the page does not need to be reloaded.

how can the ajax call keep happening all the time by itself ?


It doesn't. Ajax calls get made when the script makes them.


¹Note that it is not uncommon to use JSP to render HTML fragments to send as the response to Ajax calls. So it's not necessarily always one or the other.
 
Ranch Hand
Posts: 43
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I heard jQuery (or dojo) can make ajax call (xhr) to server to get json data and display them on the page.
But this thing can be done using jsp too (jsp cna get java bean and render it on page). What's the difference and advantage of jquery or dojo call ?



1st of all, using JSP alone, you can't make Ajax call. Using Java Script in JSP (or any such category) only you can make Ajax call. So, IMO, the question is why JQuery or Dojo when Java Script alone can do it? If this is the case, the answer will be using Java script, you will have to write lots of code from scratch which can be done easily by calling just apis from JQuery or Dojo.
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. javascript makes ajax call and load json data on page, fine. Now my question is --- suppose a section of page <div> uses javascript to make ajax call to get data, if the server side data changes, does this section of page gets refreshed automatically ? If not, what's the advantage of ajax ?
 
Amar Saikia
Ranch Hand
Posts: 43
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

if the server side data changes, does this section of page gets refreshed automatically ?

Yes. It will. However, to work it automatically, you will have to write Ajax code accordingly. For example, you will have to use the response data to replace the old section inside <div> using javascript.
 
Bear Bibeault
Sheriff
Posts: 67590
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

ben oliver wrote:suppose a section of page <div> uses javascript to make ajax call to get data


That wording doesn't make much sense. elements do not use Javascript. Most script executes as the result of an event.

if the server side data changes, does this section of page gets refreshed automatically ?


No. Something needs to trigger the script that makes an Ajax call.

If not, what's the advantage of ajax ?


Otherwise, you cannot change the page with server-side data or markup without reloading the whole page.
 
Bear Bibeault
Sheriff
Posts: 67590
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

Amar Saikia wrote:Yes. It will.


No, it won't. Data changing on the server will in no way be automatically reflected on the client.
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

Amar Saikia wrote:Yes. It will.


No, it won't. Data changing on the server will in no way be automatically reflected on the client.



I guess I get it --- In old JSP approach, you have to repload the entire page to get updated server side data. But for ajax, you may use some event (click a link, expand a section ,etc) to trigger ajax call to load some server side new data without loading the entire page, only that portion of page will be refreshed. Correct ?
 
Amar Saikia
Ranch Hand
Posts: 43
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amar Saikia wrote:
Yes. It will.

No, it won't. Data changing on the server will in no way be automatically reflected on the client.



I think there is confusion about the word 'automatic' which only the original poster can explain. I assumed that by " Data changing on the server" he means that the data changed in the server as a result of an Ajax call. Thats why I wrote

to work it automatically, you will have to write Ajax code accordingly. For example, you will have to use the response data to replace the old section inside <div> using javascript

 
Bear Bibeault
Sheriff
Posts: 67590
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

ben oliver wrote:only that portion of page will be refreshed. Correct ?


Yes.

 
Bear Bibeault
Sheriff
Posts: 67590
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

Amar Saikia wrote:I assumed that by " Data changing on the server" he means that the data changed in the server as a result of an Ajax call.


I believe he was asking about independent changes.
 
ben oliver
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I said "data change on the server", I meant the data is changed on the server side (not because of ajax call). sorry for the confusion.
 
Amar Saikia
Ranch Hand
Posts: 43
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I meant the data is changed on the server side (not because of ajax call)



Lesson learnt: We should not assume . Thanks Bear.
 
reply
    Bookmark Topic Watch Topic
  • New Topic