Q:

jQuery return [object Object] but dev tool response get what I want

In my controller have actionGetRandomCode.  Why when I shown with jQuery like this 
var ran = $.get('index.php?r=registrations/get-random-code');
alert(ran);

Its getting show [object Object]? 
But in my dev tool response I get what I want RQLGLS

A:

You need to use .done and put the alert inside it.  The Ajax methods are asynchronous so you need to use a callback function to resolve the result    
var ran = $.get('index.php?r=registrations/get-random-code').done(function(data) {
    alert( "Data: " + data );
});

