2

I'm using the prototype framework to obtain a reverse ajax effect in my page, i'm using this script:

<script language="JavaScript" src="prototype.js"></script>
<script>
Event.observe(window, 'load', function() {
connectToServer();
});

function connectToServer()
{
new Ajax.Updater(
    { success: 'asd', failure: 'error' },
    'evaluation',
    {
        method:     'get',
        onSuccess:  function(transport)
        {
            if (transport.responseText!=''){
                try {
                    eval(transport.responseText)
                } catch (e) {
                    alert(e.message);
                }
            }
            connectToServer();
        },
    });
 }
 </script>

The script works correctlty but i have a problem, when i shutdown the web server (in my case a little web server i wrote in python) a lot of exception are thrown due to error 404, is there a way to catch this exception and block the script?

Luca
  • 1,270
  • 1
  • 18
  • 34

1 Answers1

3

Add an on404 option to the Ajax.Updater options, pass a function handler like you have done for onSuccess.

the on<HTTPSTATUSCODE> handler will prevent the onSuccess from firing only if the HTTP code exists as a handler. ie If the webserver responds with a 500 error and you only have a on404 handler defined, onSuccess might still run, but shouldn't because success is defined as any of the 200s status codes.

Geek Num 88
  • 5,264
  • 2
  • 22
  • 35
  • ok, now it says only once 'Failed to load Resource', i changed the onSuccess to on200, but how can i catch the 'failed to load event'? for example i want to show a pop up on this event – Luca Jan 14 '13 at 22:12
  • I'll check it out - its in the documentation so it "should" work.... You might want to try the `onFailure` handler – Geek Num 88 Jan 15 '13 at 15:32