Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Is it common and/or acceptable to have Ajax requests every time a button is clicked on a shopping cart page? This is not a high traffic site. It will only have a few users at a time, like 5 max. I'm calling it a shopping cart for lack of a better term. The site is intended to let customers create highly customized orders, which benefits from logic being on the server instead of on the client.

I have many questions regarding the best practices in this sort of design. Like, should I block user input until the ajax request is received? Should I be sure to display an error message if the ajax request fails? Should I automatically repeat the ajax request if it fails? Are there any other considerations?

share|improve this question
1  
please have a look meta.stackoverflow.com/questions/5234/… –  Yusubov Jul 29 '12 at 4:16
add comment

2 Answers

up vote 1 down vote accepted

It looks like you are interested in best practices to follow or just use in your case. There are a number of written article on this subject matter, however there are few good once that combine techniques in one as well :)

Regarding your questions, i would skip the one saying "Should I automatically repeat the ajax request if it fails?" - No, just process the failure message in user friendly way.

More readings on best practices with Ajax calls:

share|improve this answer
1  
re: "the perfect jquery ajax request"... that post looks to be a bit dated. If you're interested, there's another awesome one that (though still dated a bit - jquery 1.5) uses jquery deferred here: erichynds.com/jquery/using-deferreds-in-jquery –  Steve Evers Jul 25 '12 at 17:28
    
yeap, it is not recent jquery library, however it illustrates the handling of failed requests. –  Yusubov Jul 25 '12 at 17:39
    
Hey, sorry it took so long to reply. I didn't notice the notification. Great links, thanks for the help. –  David Jul 30 '12 at 15:04
    
@David, no problem and thx ! –  Yusubov Jul 30 '12 at 15:24
add comment

should I block user input until the ajax request is received?

Only if user actions should be blocked. For example, if you're updating the cart total there is no need to block. But if the user is removing an item from the cart, you probably need to complete processing and recalculate before allowing them to manipulate something else in the cart. To put it simply, only block user input when necessary but be sure to consider every situation where it is really necessary.

Should I be sure to display an error message if the ajax request fails?

If it will matter to the user then yes, display a user-friendly message. For example, if removing an item from the cart fails, the user will not see their action succeed, or may see incorrect information. That must be handled correctly with the user. Be sure the backend properly logs the error so by the time the user reports it there's a solution.

Should I automatically repeat the ajax request if it fails?

Maybe if it fails from a timeout, but otherwise no. No need to repeat something that will likely fail.

Are there any other considerations?

Lots! If you ask more specific questions we can give you more specific answers. In short, I would say think of your AJAX calls just as any other subsystem with architectural, performance, maintenance and user considerations.

share|improve this answer
    
Thanks for clarifying. I upvoted your answer. Sorry for the delay getting back. –  David Jul 30 '12 at 15:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.