GetSimple Support Forum
Some javascript problems in admin area - Printable Version

+- GetSimple Support Forum (http://get-simple.info/forums)
+-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3)
+--- Forum: General Questions and Problems (http://get-simple.info/forums/forumdisplay.php?fid=16)
+--- Thread: Some javascript problems in admin area (/showthread.php?tid=3143)



Some javascript problems in admin area - alorence - 2012-04-30

I recently discover a problem with 3.1B version. In admin area, on file admin/template/header.php, this piece of code generated an uncaught exception :
Code:
var obj = jQuery.parseJSON('<?php echo get_api_details(); ?>');
if(obj.status != 1) {
    $('a.support').parent('li').append('<span class="warning">!</span>');
    $('a.support').attr('href', 'health-check.php');
}

We use getsimple for a project hosted on sourceforge. On this host service, all outbound communications are forbidden (http://sourceforge.net/apps/trac/sourceforge/wiki/Project%20web%20and%20developer%20web%20platform#Outboundconnectivity) and the PHP function "get_api_details()" returns an empty string.

As mentionned in jquery docs http://api.jquery.com/jQuery.parseJSON/, the parseJSON method returns null if an empty strings is passed in parameter, so reading obj.status directly after calling parseJSON can end with an error. This error causes many Javascript codes to not be executed in the rest of page (especially with the i18n_navigation plugin).

To prevent these king of problem, it is possible to control that obj is different from null before reading its status property. Moreover, as mentionned in jQuery doc, parseJSON method can throws exceptions if malformed JSON is gave as parameter. So I would like to suggest this code to replace the one mentioned above :
Code:
try {
    var obj = jQuery.parseJSON('<?php echo get_api_details(); ?>');
    if(obj != null && obj.status != null && obj.status != 1) {
        $('a.support').parent('li').append('<span class="warning">!</span>');
        $('a.support').attr('href', 'health-check.php');
    }
} catch(error){
    //Something to do ?
}



Some javascript problems in admin area - shawn_a - 2012-04-30

Absolutely

Created issue
http://code.google.com/p/get-simple-cms/issues/detail?id=320