Q:

Refresh jquery object after ajax

I have a lucky spin script that need to get random number from database and let it spin to the number.
The problem is, after document.ready, I cant assign any value to the object option again.
<input type="button" value="test" id="playBtn" onclick="getluckynumber();"/>
    <input type="button" id="fire" style="visibility:hidden;"/>
    <input type="hidden" id="luck" value=""/>

function getluckynumber(){
            $.ajax({
                url:"ajax.php",
                method:"POST",
                data:{event_id:'<?=$event_id ?>'},
            })
                    .done(function(data){
                        $("#luck").val(data);
                        $("#fire").trigger("click"); 
                    });
        }

        $(document).ready(function(){
            $('.slot').jSlots({
                spinner:'#fire',
                endNumbers:$("#luck").val(),
            });
        });

How to make the "endNumbers" to take new value?
UPDATE:
https://jsfiddle.net/asaxpse3/1/
UPDATE:
The final working code
var getNewNumber=function(spinner){
        $.ajax({
            url:"ajax.php",
            method:"POST",
            async:false,
            data:{event_id:'23'},
        })
                .done(function(data){
                    if(data){
                        spinner.options.endNumbers=JSON.parse(data);
                        //console.log(data);
                    }
                });
    };

    $(document).ready(function(){
        $('.slot').jSlots({
            spinner:'#playBtn',
            onStart:getNewNumber
        });
    });

Thanks to skobaljic.

A:

You can bind the function on onStart option, but you have to change the plugin code and provide the spinner instance as parameter:
if ($.isFunction(base.options.onStart)) {
    base.options.onStart( base );
}

Than you should define the random number function generator, for example:
var getNewNumber = function( spinner ) {
    /* Some SYNC!! ajax stuff, than when done: */
    //the returned data is a array, eg [1,3,4]
    //for the spinner to stop at 134
    spinner.options.endNumbers = [1, 3, 4];
};

And at the end, bind the generator function to plugin's onStart option:
$('.slot').jSlots({
    spinner: '#playBtn',
    endNumbers: [],
    onStart: getNewNumber
});

Please note: The AJAX must be sync, use param async: false.
Complete code here

