开发者

Notify about errors?

I have this script that allows a user to 开发者_运维百科rate a website but an error will be displayed when a user tries to leave or rate the website before the page loads which will confuse the user that there rating didn't go thru when it actually did. So I was wondering is it really necessary to display the error or can I leave the following error code out of my script? Is it okay?

error code.

        error: function(result) {
            alert("some error occured, please try again later");
        } 

Here is the JavaScript code.

function getRating(){
    $.ajax({
        type: "GET",
        url: "http://www.example.com/",
        data: "do=getrate",
        cache: false,
        success: function(result) {
            // apply star rating to element dynamically
            $("#rating").css({ width: "" + result + "%" });
             // add rating text dynamically
            $("#new-rating").text(getRatingText());
        },
        error: function(result) {
            alert("some error occured, please try again later");
        }
    });
}


It's always better to notify users of things that went wrong.

I suggest giving an explanation what might have happened, so they can decide on their own if that's a good or bad thing.

Remember - technology will always fail somehow. Imagine your server having a database error and can't store those ratings. The client/user will never know about that, if you ignore those errors. On the other hand, if you display a warning, users might at least have the chance to send you an email about it.


Users can barely be bothered to rate something once. Asking them to try again later is of absolutely no value, especially since you've presumably already achieved your goal of getting the rating from them.


If you don't handle the error and tell the user about it, they won't be made aware of it any other way. If that's okay to you, then don't tell them about it. But it's usually best practice, if the user asks the page to do something and it can't, to say that it couldn't.

Does the page you're posted the data to actually return an HTTP failure code if it doesn't work? For instance, a 500 error if the database is down? Because if not, if you're returning some text saying the database didn't work, then your success function needs to handle that application level failure, because the ajax request succeeded — it's just that the server-side action failed.


An alert may be annoying. Possibly you could put the error message in the page in place of the rating, perhaps with a style that draws attention, but even that may be excessive. It all depends on how much attention-grabbing you feel is appropriate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜