• 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

ajax on the server

 
Bartender
Posts: 1810
28
jQuery Netbeans IDE Eclipse IDE Firefox Browser MySQL Database Chrome Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Perhaps what you really want to delve into is RESTful web APIs?


Maybe. I've written code to consume RESTful services, but never to generate them. I need to look into that.

Bear Bibeault wrote:P.S. I don't see any issues with sometimes returning JSON and sometimes HTML; I do it all the time. It depends upon usage and the needs of the API.


That's reassuring. But I feel like I'm missing something. If you'll indulge me for a moment...

I usually write an "AjaxHandler" class that looks something like this:

Except for the lack of logging, that looks like decent code to me. But this:

That looks hideous to me with all that String appending going on and I can't help but think that there has to be a better way. That' why I asked about improving my server-side code. I feel like there must be techniques that I just haven't learned yet, because it's hard to believe that this is the best way to do it. Is this really an acceptable solution, or have I wandered off into the wilderness?
 
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

J. Kevin Robbins wrote:That looks hideous to me with all that String appending going on and I can't help but think that there has to be a better way.


There is: JSP (or other templating technology). Building up HTML markup in strings is a horrible thing to do.

because it's hard to believe that this is the best way to do it. Is this really an acceptable solution, or have I wandered off into the wilderness?


Get out your machete!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic