Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print json array in jquery with ajax response

i am newbie in JSON. i just started learning JSON before 30 mins.

i want to print JSON array in jquery.

 $.ajax({
                url : '/exp/resp.php',
                type : 'POST',
                dataType : 'json',
              //  data : 'uname='+uname+'&pass='+pass,
                success : function (data)
                {
                    alert(data);

                }
            });

now it's printing abc,def,ghi,jkl,mno. so i want to print it separate like abc def ghi etc.. i referred this answer but it didn't help...

like image 913
404 Not Found Avatar asked Nov 29 '22 15:11

404 Not Found


2 Answers

Why not print something generic like:

JSON.stringify(data);

This should work with either an object or an array.

like image 115
Daryl Avatar answered Dec 10 '22 23:12

Daryl


if data is an array then

alert(data.join(' '));
like image 33
Arun P Johny Avatar answered Dec 11 '22 01:12

Arun P Johny