crazedsanity / cs-battletrack

PHP-Based web application for tracking data in traditional paper-and-pencil role playing games.
http://www.crazedsanity.com/projects/cs-battletrack
Other
1 stars 1 forks source link

Change AJAX to use JSON instead of XML #51

Closed crazedsanity closed 7 years ago

crazedsanity commented 10 years ago

All the code that handles AJAX updates currently uses XML. While this might be easy enough to understand on the PHP side, it becomes rather confusing on the Javascript side.

It exists in sample_scripts/js/ttorp.js on around line 165 (as of v0.9.14). The XML parsing in Javascript is basically this:

if($(xmlObj).find('changesbykey').text()) {

        for (var iNode = 0; iNode < xmlObj.childNodes.length; iNode++) {
            var node = xmlObj.childNodes.item(iNode);
            for (i = 0; i < node.childNodes.length; i++) {
                var sibling = node.childNodes.item(i);
                for (x = 0; x < sibling.childNodes.length; x++) {
                    var forceChange = false;
                    var sibling2 = sibling.childNodes.item(x);
                    if(sibling2.nodeName == forceNameChange) {
                        forceChange=true;
                    }
                    if (sibling2.childNodes.length > 0) {
                        var sibling3 = sibling2.childNodes.item(0);
                        markUpdatedInput($("#" + sibling2.nodeName), sibling3.data, forceChange);
                    }
                    else if(sibling2.nodeName.match(/^[aZ-zZ]/)) {
                        //This handles clearing-out data.
                        markUpdatedInput($("#" + sibling2.nodeName), "", forceChange);
                    }
                }
            }
        }
    }
crazedsanity commented 7 years ago

Convert to JSON instead of XML for AJAX

crazedsanity commented 7 years ago

While there's still a lot of code cleanup to do, this is now implemented. Much nicer to work with JSON than XML.