Skip to content

Instantly share code, notes, and snippets.

@jyeary
Last active November 9, 2018 20:40

Revisions

  1. jyeary revised this gist Jul 9, 2015. 1 changed file with 24 additions and 2 deletions.
    26 changes: 24 additions & 2 deletions jsf.ajax.handler.js
    Original file line number Diff line number Diff line change
    @@ -22,9 +22,31 @@ jsf.ajax.addOnError(function(data) {
    message += '\nError: ' + errorName.stringValue;
    message += '\nMessage: ' + data.errorMessage;
    alert(message);
    //TODO Take Additional actions
    //TODO Take Additional actions.
    });

    jsf.ajax.addOnEvent(function(data) {
    alert(data.source.id + " " + data.type + " " + data.status);
    });
    });

    function handleAjax(data) {
    var status = data.status;
    switch (status) {
    case "begin":
    // This is the start of the AJAX request.
    //TODO Take action here.
    break;
    case "complete":
    // This is invoked right after AJAX response is returned.
    //TODO Take action here.
    break;
    case "success":
    // This is invoked right after successful processing of AJAX response and update of HTML DOM.
    alert("The AJAX responseCode was: " + data.responseCode);
    //TODO Take Additional actions.
    break;
    }
    }

    // Setup the statusUpdate function to hear all events on the page
    jsf.ajax.addOnEvent(handleAjax);
  2. jyeary created this gist Jan 19, 2014.
    30 changes: 30 additions & 0 deletions jsf.ajax.handler.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    /*
    * Copyright 2012-2014 John Yeary <[email protected]>.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
    *
    * http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
    jsf.ajax.addOnError(function(data) {
    // This shows how to get the information via XPath, but it is not required. The error name can be found using data.errorName
    var errorName = data.responseXML.evaluate('//error/error-name', data.responseXML, null, XPathResult.STRING_TYPE, null);
    var message = 'AJAX Exception';
    message += '\nSource: ' + data.source.id;
    message += '\nValue:' + data.source.value;
    message += '\nError: ' + errorName.stringValue;
    message += '\nMessage: ' + data.errorMessage;
    alert(message);
    //TODO Take Additional actions
    });

    jsf.ajax.addOnEvent(function(data) {
    alert(data.source.id + " " + data.type + " " + data.status);
    });