Changeset 1684 in ExiteCMS


Ignore:
Timestamp:
08/25/08 17:39:15 (3 years ago)
Author:
hverton
Message:

added error handling code to the ajaxcall function (timeouts, http errors, url errors). Now null will be the return value when an error has occured (to avoid 0 == false issues!)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/jscripts/core_functions.js

    r1659 r1684  
    5959 
    6060// update the innerHTML of 'id' using an AJAX call 
    61 function clientSideInclude(id, url) { 
     61function clientSideInclude(id, url, error) { 
    6262 
    6363    var element = document.getElementById(id); 
     
    6767    } 
    6868    var response = AjaxCall(url); 
    69     if (response != false) { 
     69    if (response != null) { 
    7070        element.innerHTML = response; 
    7171    } else { 
    72         element.innerHTML = "Sorry, your browser does not support XMLHTTPRequest objects. This page requires Internet Explorer 5 or better for Windows, or Firefox for any system, or Safari. Other compatible browsers may also exist."; 
    73     } 
    74 } 
    75  
    76 // simple synchronous AJAX call 
     72        if (error != null && error) { 
     73            element.innerHTML = "Sorry, your browser does not support XMLHTTPRequest objects. This page requires Internet Explorer 5 or better for Windows, or Firefox for any system, or Safari. Other compatible browsers may also exist."; 
     74        } 
     75    } 
     76} 
     77 
     78// simple synchronous AJAX call, return null when it fails 
    7779function AjaxCall(url) { 
    7880 
     
    98100    } 
    99101    if (req) { 
    100         // Synchronous request, wait till we have it all 
    101         req.open('GET', url, false); 
    102         req.send(null); 
    103         return req.responseText; 
    104     } else { 
    105         return false; 
     102        try { 
     103            // Synchronous request, wait till we have it all 
     104            req.open('GET', url, false); 
     105            req.send(null); 
     106            if (req.status != 200) { 
     107                return null; 
     108            } else { 
     109                return req.responseText; 
     110            } 
     111        } catch (e) { 
     112            return null; 
     113        } 
     114    } else { 
     115        return null; 
    106116    } 
    107117} 
Note: See TracChangeset for help on using the changeset viewer.