• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting data from the server with Ajax

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Finally think I have this 87.5% figured out - found the code and adapted it.

Not sure I fully understand what's happening here but it does work.

If someone could comment it out, I'm sure there are some of us that would like to understand it better (and possibly make it more efficient.)
(also found a JQuery version but could not get it working.)

 
Sheriff
Posts: 67746
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
I think you'd be better off pursuing the jQuery version. Dealing with cross-browser Ajax is just too much trouble to bother with.

All of that would reduce to a line or two with jQuery.
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I think you'd be better off pursuing the jQuery version. Dealing with cross-browser Ajax is just too much trouble to bother with.

All of that would reduce to a line or two with jQuery.



can you share (how to code) the JQuery version, for us novices??
 
Bear Bibeault
Sheriff
Posts: 67746
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
Sure I can get you started with some skeleton code. To load an HTML fragment into the DOM:
Yes, that's all.

For a more general get, such as you appear to be doing:
 
Bear Bibeault
Sheriff
Posts: 67746
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
Btw, why XML? It's painful to deal with. JSON is much preferred when returning data via Ajax.
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Btw, why XML? It's painful to deal with. JSON is much preferred when returning data via Ajax.



Right now it's the easiest to implement. I can have a VA take the XML template and just update the info and FTP to subdirectory.

My ultimate goal - which you mentioned before - is to have a DB on the back end (which would also eliminate the need for subdirectories and duplicating all the HTML & images files??) and have all users access the site via a unique URL (ie. www.kwmds.com?User#1), then have the "same" page served dynamically.

Based on what I'm reading here and on other sites I'm guessing its relatively easy to implement - IF YOU KNOW WHAT YOU'RE DOING - and of course I'm starting at ground zero
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Sure I can get you started with some skeleton code. To load an HTML fragment into the DOM:
Yes, that's all.


OK - breaking this down for the newbie...

(#idOfParent) = the ID my HTML is using?
.load = jQuery method
('/url/to/resource') = link to my XML file?

Question 1 - how do I pass the fact that I only need the "agent" tag?
Question 2 - "agent" has 6 lines of data. Will the .load method return all 6 or do i need iterate through?

version of the XML file below...

 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bill Hamberg wrote:

Bear Bibeault wrote:Sure I can get you started with some skeleton code. To load an HTML fragment into the DOM:
Yes, that's all.


OK - breaking this down for the newbie...

(#idOfParent) = the ID my HTML is using?
.load = jQuery method
('/url/to/resource') = link to my XML file?

Question 1 - how do I pass the fact that I only need the "agent" tag?
Question 2 - "agent" has 6 lines of data. Will the .load method return all 6 or do i need iterate through?



WOW - try and you shall do!semi-works; just need to break the data into separate lines!?

(this friggin JQuery stuff is cool! )
Think we just eliminate 25 lines of code?!?
 
Bear Bibeault
Sheriff
Posts: 67746
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
I would once again question the XML. I tend to make changes on the server in order to make things easier on the client, rather than the other way around.

But, once you get an XML document back as the data, you can use jQuery to select from the XML DOM the same way as the HTML DOM. For example: $('agent',xmlDoc).text()

Granted, I've never done that (I use XML for many things, but returning it to a client as an Ajax response would never be one of them) so there may be nuances I've missed.
 
Bill Hamberg
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I would once again question the XML...



It was the easiest (shortest learning curve) path at the time.

Bill Hamberg wrote:My ultimate goal - which you mentioned before - is to have a DB on the back end (which would also eliminate the need for subdirectories and duplicating all the HTML & images files??) and have all users access the site via a unique URL (ie. www.kwmds.com?User#1), then have the "same" page served dynamically.

Based on what I'm reading here and on other sites I'm guessing its relatively easy to implement - IF YOU KNOW WHAT YOU'RE DOING - and of course I'm starting at ground zero



So now that that is working what resources would you recommend (reading/hiring) to implement the database solution?

 
Bear Bibeault
Sheriff
Posts: 67746
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
Any decent book on web development. Head First Servlets and JSP is good (disclaimer: I was a technical reviewer).

You might also want to read these articles to understand what JSP is all about and how to structure traditional Java web apps:
  • The Secret Life of JSPs
  • The Front Man


  • For JavaScript, there's my own Secrets of the JavaScript Ninja and though my jQuery book (jQuery in Action (2nd Ed)) is based on an older version of jQuery, all the info in it is still good enough to get you going.
     
    Bill Hamberg
    Greenhorn
    Posts: 16
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    THANKS!!!
    reply
      Bookmark Topic Watch Topic
    • New Topic