Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to alert javascript object

Tags:

javascript

I am trying to study the jquery class, but I have a hard time debugging an object because I can't see the element inside of it

$("#birds").autocomplete({
    source: "search.php",
    select: function (event, ui) {
        alert(ui);
    }
});

it returns [object Object].. :( My question is how can I alert the object so that I can see the element?

like image 695
mapet Avatar asked Aug 27 '10 01:08

mapet


2 Answers

i recommend you use FireBug for debugging javascript. then you can just do

console.log(ui) 

and it'll log the object in a form you can expand

like image 120
Scott Evernden Avatar answered Oct 12 '22 17:10

Scott Evernden


Just convert your object to a JSON object using stringfy.

alert(JSON.stringify(yourObjectVariable));

simple as pie :)

like image 45
Shafin Mahmud Avatar answered Oct 12 '22 18:10

Shafin Mahmud