Home > Web Development > Good JQuery Helper Functions

Good JQuery Helper Functions




Good Jquery helpers functions.

I use this method from encosia to clean up the d returned by

micrsoft when making json calls:

        function filterJSON(data) {
            var msg;
            if (typeof (JSON) !== 'undefined' &&
                    typeof (JSON.parse) === 'function')
                msg = JSON.parse(data);
            else
                msg = eval('(' + data + ')');
            if (msg.hasOwnProperty('d'))
                return msg.d;
            else
                return msg;
        }

Taken from Dave here: http://encosia.com/2009/07/21/simplify-calling-asp-net-ajax-services-from-jquery/

This ones for dumbing a json object that get’s returned as a data object

using this person’s helper method:

http://schotime.net/blog/index.php/2008/07/27/dataset-datatable-to-json/comment-page-1/#comment-223

function outputDT(dataTable) {
            var headers = [];
            var rows = [];
            headers.push("<tr>");
            for (var name in dataTable[0])
                headers.push("<td><b>" + name + "</b></td>");
            headers.push("</tr>");
            for (var row in dataTable) {
                rows.push("<tr>");
                for (var name in dataTable[row]) {
                    rows.push("<td>");
                    rows.push(dataTable[row][name]);
                    rows.push("</td>");
                }
                rows.push("</tr>");
            }
            var top = "<table border='1'>";
            var bottom = "</table>";
            return top + headers.join("") + rows.join("") + bottom;
        }

Tags:
  1. No comments yet.
  1. No trackbacks yet.