From d6fadc5302500cab1e6801b42e4df7de9aa5cfdc Mon Sep 17 00:00:00 2001 From: Nicolas Boisselier Date: Tue, 11 Aug 2015 02:37:09 +0100 Subject: [PATCH] Fix this.form_submit_clean action attribute bug --- lib/js/nb.js | 98 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/lib/js/nb.js b/lib/js/nb.js index 48f94bee..8b227793 100644 --- a/lib/js/nb.js +++ b/lib/js/nb.js @@ -4,39 +4,29 @@ * Date: 28.03.15 * See: http://www.w3schools.com/jquery/jquery_ref_selectors.asp */ +var nb = new NB(); function NB() { this.form_submit_clean = function(f) { var i = 0; - var msg = ''; var url = ''; - msg += f.action + '\n'; + var action = f.getAttribute('action'); + + //if (typeof(action) == 'undefined') action = ''; for(i=0;i' - + (url) - + '' - ); - return false; - } - */ - //if (url == window.location) return false; window.location = url; return false; @@ -74,7 +64,7 @@ function NB() { if ((xhr.readyState == 4) && (xhr.status == 200)) xhr_content = xhr.responseText; } - catch (e) { console.log (e) } + catch (e) { console.log ('NB.get_http:'+e) } return xhr_content; }; @@ -122,32 +112,60 @@ function NB() { }; - this.json_debug = function(url) { - $.getJSON(url,function(data) { - var tag = ''; - if (typeof(data) == 'string') { - tag = 'span'; - } else if ($.isArray(data)) { - tag = 'ul'; - } else { - tag = 'fieldset'; + this.data2html = function(data) { + + if (typeof(data) == 'string') { + //if (data == '') return ' '; + return data; + } + + var items = []; + + if ($.isArray(data)) { + if (!data.length) return ''; + + if (typeof(data[0]) == 'object') { + for (var i=0;i'+val+'' ); - } else if (tag == 'fieldset') { - items.push( '
'+key+'
'+val+'
' ); + + for (var i=0;i'+nb.data2html(data[i])+'' ); + } else { + items.push( '
  • '+data[i]+'
  • ' ); } - }); - $( '<'+tag+'/>', { - //"class": "my-new-list", - html: items.join( "" ) - }).prependTo( "#msg" ); + } + return '
      ' + items.join('') + '
    '; + + } + + var key = ''; + var val = ''; + for (var key in data) { + val = data[key]; + if (typeof(val) != 'string') { val = nb.data2html(val); } + //items.push( '' + key + '' + val + '' ); + items.push( '
    ' + key + '
    ' + val + '
    ' ); + //items.push( '
    ' + key + '
    ' + val + '
    ' ); + } + + //return '' + items.join('') + ''; + return items.join(''); + return '
    ' + items.join('') + '
    '; + return '
    ' + items.join('') + '
    '; + return '
    ' + items.join('') + '
    '; + } + + this.json2html = function(url) { + $.getJSON(url,function(data) { + if ($.isArray(data) && data.length == 1) data = data[0]; + var html = nb.data2html(data); + //console.log(nb.data2html(data)); + if (html != '') $(html).prependTo( "#msg" ); //console.log(typeof(data)); }); } -- 2.47.3