I am creating new functionality where I build a grid based on Json data returned from Ajax. I have decided I want to encapsulate this functionality within a function, so when I add/update/delete, I can on success retrieve a new representation of the data.
The problem I am having is I want to fill a global array but once my function that uses AJAX ends, I have an Array but no data. This isn't a problem when all the code is within the AJAX call but once I try to separate this in to its own function, it doesn't work as intended.
 <script type="text/javascript">
    var DataArray = [];
    // Use this function to fill array
    function retrieveNotes() {
        $.ajax({
            url: "http://wks52025:82/WcfDataService.svc/GetNotesFromView()?$format=json",
            type: "get",
            datatype: "json",
            asynch:true,
            success: function (data) {
                returnedData = data;
                $.each(data.d, function (i, item) {
                    DataArray[i] = [];
                    DataArray[i][0] = item.NotesTitle.trim();
                    DataArray[i][1] = item.ProfileName.trim();
                    DataArray[i][2] = item.IsShared;
                    DataArray[i][3] = item.NameOfUser.trim();
                }) // End of each loop
            }
        });
    }
    $(document).ready(function () {
        retrieveNotes();
        DataArray;
    </script>

asynch:true,---async2. read what it means in jquery documentation