This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Wrapping jQuery Ajax Convenience Methods: Good idea or bad idea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Wrapping jQuery Ajax Convenience Methods: Good idea or bad idea" Watch "Wrapping jQuery Ajax Convenience Methods: Good idea or bad idea" New topic
Author

Wrapping jQuery Ajax Convenience Methods: Good idea or bad idea

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

We're using jQuery's load() function a lot throughout our application. We've discovered, quite embarrassingly I might add, that we need better error handling. So instead of



we need to use



So that we can check the status and deal with things appropriately. I'm thinking of writing a wrapper around load() (among other things) that would allow us to write code like this (function name for demo only):



But as I look at that, it makes me think I should just use the $.ajax() function instead, since I can already do that. So what would be a better "standard"? Wrap the convenience methods or just fall back to .ajax() ?


GenRocket - Experts at Building Test Data
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

If it's centralized error handling you are after, I'd just use the jQuery error events.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Bear Bibeault wrote:If it's centralized error handling you are after, I'd just use the jQuery error events.


Yea, I'm already doing that for some things. However, these error handling bits aren't all generic. For example, in this one instance on a load() call, I am showing and hiding some elements on success. But if there was an error, I don't want to show/hide things. I need to basically not do anything.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60810
    
  65

I generally fall back to $.ajax in similar circumstances, unless it's something that will be done again and again and again, in which case extending/wrapping would be a decent approach.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Bear Bibeault wrote:I generally fall back to $.ajax in similar circumstances, unless it's something that will be done again and again and again, in which case extending/wrapping would be a decent approach.


That's what I figured and just needed that confirmation. Thanks.
 
jQuery in Action, 2nd edition
 
subject: Wrapping jQuery Ajax Convenience Methods: Good idea or bad idea
 
Similar Threads
Making a Post request using Ajax
Writing JSON data back to client
remove carriage return from string
Page section does not update after call of a4j:support in IE 9
Location of DOJO Error Messages