54 | | * see how we run a SERQL query from javascript, parse the results using ultra-cool jsolait framework and render HTML of it. |
| 54 | * see how |
| 55 | * '''we run a SERQL query from javascript, ''' |
| 56 | * '''parse the results using ultra-cool jsolait framework''' |
| 57 | * '''and render HTML of it.''' |
| 58 | |
| 59 | using only these lines of code: |
| 60 | {{{ |
| 61 | function runSerqlExample() |
| 62 | { |
| 63 | // turn debug alerts off |
| 64 | gnowsis_showdebugalert = false; |
| 65 | var formC = document.forms["formserqlexample"]; |
| 66 | var queryString = formC.elements["rquery"].value; |
| 67 | try { |
| 68 | var res = gnowsis_callXmlMethod("gnowsis-server", "dataaccess", "querySelect", |
| 69 | queryString, "serql"); |
| 70 | } catch (e) |
| 71 | { |
| 72 | alert("error querying: "+e); |
| 73 | } |
| 74 | renderSerqlExample(res); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * render the serql query result. |
| 79 | * query result is a vector of hashmaps, pretty easy. |
| 80 | */ |
| 81 | function renderSerqlExample(res) |
| 82 | { |
| 83 | gnowsis_debug("rendering table"); |
| 84 | var render = "<table>"; |
| 85 | for (var i = 0; i < res.length; i++) |
| 86 | { |
| 87 | var row = res[i]; |
| 88 | |
| 89 | // render header? |
| 90 | if (i==0) |
| 91 | { |
| 92 | render+="<tr>"; |
| 93 | for (col in row) |
| 94 | { |
| 95 | render += "<td>"+col+"</td>"; |
| 96 | } |
| 97 | render += "</tr>"; |
| 98 | } |
| 99 | |
| 100 | // render row |
| 101 | render+="<tr>"; |
| 102 | for (col in row) |
| 103 | { |
| 104 | render += "<td>"+row[col]+"</td>"; |
| 105 | } |
| 106 | render += "</tr>"; |
| 107 | } |
| 108 | render += "</table>"; |
| 109 | var exampleOut = document.getElementById('SerqlExampleoutput'); |
| 110 | gnowsis_debug(render); |
| 111 | exampleOut.innerHTML = render; |
| 112 | gnowsis_debug("finished"); |
| 113 | } |
| 114 | }}} |