tags:

views:

44

answers:

3

for example:

user submit a comment , I add the comment in the page by javascript , then do the ajax. if ajax post failed ,tell user that something wrong happend.

in this way , it can improve user experience . and the probability of ajax failed is not low. but I didn't seen which site is using this technology , so is this method possible?

A: 

Yes there is nothing stopping you doing this.

You add the comment in an element you create in javascript post the data and get the response code back form the ajax post.

Paul Whelan
+1  A: 

Actually, I'd say that stackoverflow uses this technique :

  • Make sure you are using firebug, and have the console displayed on the bottom of your browser scree
  • Click on (for instance) the arrow to upvote
  • you will see the arrow immediatly becomes orange, to indicate you have upvoted)
  • but looking at firebug's console, you will see the Ajax request starts only after the arrow has changed color -- or, at least, it is not finised yet when the arrow has changed color.

Considering the probably of the Ajax request failing is pretty low, changing the arrow immediatly indicates the user his vote has been taken into account... Even if it's not true before a couple milliseconds ;-)

Pascal MARTIN
+1 - For explaining how to show that the comment hasn't been updated yet, but helping with a better user experience.
James Black
+1  A: 

You can add the comment via Javascript but you've also pointed out exactly why you shouldn't: what if it fails? Do you then remove the content?

In my opinion, adding it to the page implies to the user that it has worked. I would leave the comment in a form field until the AJAX submit succeeds. If that fails you can tell the user and they can try to submit again or whatever.

Of course, there is no functional reason why you couldn't do this.

cletus