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

452
November 23, 2016, at 9:35 PM

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

Answer 1

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 );
});
Rent Charter Buses Company
READ ALSO
Jquery Submit button Submission not working

Jquery Submit button Submission not working

The above jquery code is used for validating the size of file which is uploaded, width and height dimensions of an image which is being uploaded. The above script is working when file of wrong size and wrong width and height dimensions is being uploaded....

526
Why double encode Jquery Ajax URL

Why double encode Jquery Ajax URL

In my JS I use the jQuery ajax function. .

678
Wildcard in jquery autocomplete field name

Wildcard in jquery autocomplete field name

I need a wildcard for digits that come after my #TagEntry in this jquery selector. I tried the code below and a number of other variations but it does not work.

603
Asp MVC best practice: use ajax or Ajax Helper? [closed]

Asp MVC best practice: use ajax or Ajax Helper? [closed]

In ASP MVC is possible to make a post using the Ajax Helper.

464