Pass saved localStorage JSON response to datatable possible?

Pass saved localStorage JSON response to datatable possible?

monolithmonolith Posts: 3Questions: 3Answers: 0
edited November 2014 in Free community support

I have an AJAX JSON response saved to localStorage. I keep getting errors trying to pass it. Anyone know if this is possible?

 <?php

   $nonce = wp_create_nonce("get_json_users_nonce");
    $link = admin_url("admin-ajax.php?action=get_json_users&nonce=$nonce");



?>
    <script>
        $.ajax({
            url: '<?php echo $link; ?>',
            dataType: 'JSON',
            success: function(data, status) {
                $.each(data, function(key, value){
                    //handle the data                
                });

                var dataToStore = JSON.stringify(data);
                //alert(dataToStore);
                if(!localStorage.getItem('jsonUserData')){
                    localStorage.setItem('jsonUserData', dataToStore);
                }
                else{
                    //alert('Saved Data '+ localStorage.getItem('jsonUserData'));
                }
            },
            error: function() {
                alert(error);
                console.log(error);
            }
        });
    </script>
<?php
$transient = get_transient( 'player_json' );
if ( empty( $transient ) ){

    // Provide your data here

   set_transient('player_json', json_encode($link), 60*60*12 ); 
} else {

}

//echo $transient;
?>


<script>
    $(document).ready(function() {
        var table = $('#qb-list').DataTable( {
            'processing': true,
            //'serverSide': true,
            'ajax': {
                'url': 'data.json',
                'data': localStorage.getItem('jsonUserData')
            },
            //'length': 50,
            "iDisplayLength": 10,
            'deferRender':true,
        } );
        //$('#qb-section').hide();
        var style = $('#styles').val();
        var state = $('#states').val();
        var year = $('#year-select').val();
    table
        .columns(7)
        .search(state, false,true, false)
        .columns(2)
        .search(style)
        .columns(3)
        .search(year)
        .draw();
    });
</script>
This discussion has been closed.