Working with JSON Data in an AJAX call

Working with JSON Data in an AJAX call

I'm a bit of a noob with JQuery and not a rocket scientist with JavaScript, so please forgive any ignorant questions. I stay on the server side mostly.

So, I am getting JSON data back from a REST Web Service AJAX call and displaying the contents to the page in a DIV. No problem. But, I want to also allow edits on the data that comes back. Not sure how to approach this. In my "success" function of the AJAX call, I get and output the JSON data, but how do I persist this data so that it can be updated and POSTed back to the REST WS for update?

Here's my code so far. Basically, it errors because jsonPartnerData is "undefined", which confuses me. JQuery seems to complicate scoping in JavaScript.

<script type="text/javascript">
        function GetNonNull(value) {
            return (value == null) ? 'empty' : value;
        }

        var jsonPartnerData;

        // Create an anonymous self-invoking function to protect the use of $ by JQuery
        (function($){
            // Setting the default AJAX parameters here. Can easily be overridden when the AJAX call is actually made
            $.ajaxSetup({
                cache: true,
                dataType: 'json',
                timeout: 30000, //30 second timeout
                error: function (xhr, textStatus, errorThrown) {
                    alert('Error Occrurred Getting or Setting List Data: ' + errorThrown);
                }
            });

            var getPartnerListOptions = {
                type: 'GET',
                url: '/_vti_bin/ListData.svc/PartnerList',
                success: function (data, textStatus) {
                    alert('Success getting Partner List');
                    jsonPartnerData = data;
                    var startHtml = "<table border='1' style='float: left' border='1'>";
                    var endHtml = "</table>"
                    var html = "";
                    $.each(data.d.results, function (i, result) {
                        var src = result.__metadata.uri;
                        var stateId = result.StateId;
                        var stateUrl = result.State.__deferred.uri;

                        html = html + "<tr><td style='color:blue'>" + GetNonNull(result.PartnerName) +
                                        "</td><td>" + GetNonNull(result.City) +
                                        "</td><td>" + GetNonNull(src) +
                                        "</td><td>" + GetNonNull(stateId) +
                                        "</td><td>" + GetNonNull(stateUrl) + "</td></tr>";
                    });
                    $('#testOutput').append(startHtml + html + endHtml);
                }
            };

            jsonPartnerData.d.results[1].result.PartnerName = 'Test Replace Partner Name';

            var updatePartnerListOptions = {
                type: 'POST',
                url: '/_vti_bin/ListData.svc/PartnerList',
                data: jsonPartnerData,
                success: function (data, textStatus) {
                    alert('Success updating Partner List');
                }
            };

            $(document).ready(function () {
                alert('test');
                alert('Getting Partner Information!');
                $.ajax(getPartnerListOptions);


                // try and update partner information
                alert('Updating Partner Information!');
                $.ajax(updatePartnerListOptions);
            });

        }) (jQuery);

    </script>