Best method to notify a server error retrieving data.

Best method to notify a server error retrieving data.

djpabledjpable Posts: 7Questions: 0Answers: 0
edited November 2010 in General
I'd like to know the best way to raise a JS alert after a server-side error retrieving data (on re-draw for example).

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    You can use fnServerData to add your one function to get data from the server (typically using $.ajax()). Here is a an example: http://datatables.net/examples/server_side/post.html , it just needs an 'error' hander added.

    Allan
  • djpabledjpable Posts: 7Questions: 0Answers: 0
    edited November 2010
    I did:
    [code]
    jQuery.ajax( {
    "dataType": 'json',
    "type": "GET",
    "url": sSource,
    "data": aoData,
    "success": fnCallback,
    "error": function(XMLHttpRequest, textStatus, errorThrown) {
    jQuery('html').html(XMLHttpRequest.responseText);
    }
    });
    [/code]

    I did this because the web server response is HTML and i want to see the error in the current document. But i see that inspecting the dom, that the responseText is putted on the html node with an empty head and body tag.

    How can i fix this ?
  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    edited November 2010
    You need to change the selector you are giving to jQuery as it is currently writing the the 'html' element in the DOM. Perhaps something like $('div:eq(0)')... although the exact answer will depend on what you want.

    Allan
  • djpabledjpable Posts: 7Questions: 0Answers: 0
    I think the code i posted before will be ok.
    I'd like to substitute all the document from ... to ... to use all CSS, ...
    the web-server give in the case of error (So Tomcat gice his default message, IIS too, and so on).

    Thank you anyway, I think i'm off-thread right now.
This discussion has been closed.