1

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?

1

2 Answers 2

1

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:

4
  • 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 Jul 25, 2012 at 17:28
  • yeap, it is not recent jquery library, however it illustrates the handling of failed requests.
    – Yusubov
    Jul 25, 2012 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, 2012 at 15:04
  • @David, no problem and thx !
    – Yusubov
    Jul 30, 2012 at 15:24
2

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.

1
  • Thanks for clarifying. I upvoted your answer. Sorry for the delay getting back.
    – David
    Jul 30, 2012 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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