[英]how to print json array in jquery with ajax response
i am newbie in JSON. 我是JSON的新手。 i just started learning JSON before 30 mins. 我刚开始在30分钟之前学习JSON。
i want to print JSON array in jquery. 我想在jquery中打印JSON数组。
$.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 . 现在它正在打印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... 所以我想像abc def ghi等单独打印它。我提到这个答案,但它没有帮助...
Why not print something generic like: 为什么不打印像:
JSON.stringify(data);
This should work with either an object or an array. 这应该适用于对象或数组。
如果data
是一个数组那么
alert(data.join(' '));
Since your data
is an array
Check the following tutorial 由于您的data
是array
请查看以下教程
Join the elements of an array into a string: 将数组的元素加入到字符串中:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var energy = fruits.join();
The result of energy will be: 能量的结果将是:
Banana,Orange,Apple,Mango
Have a look at this http://www.w3schools.com/jsref/jsref_join.asp 看看这个http://www.w3schools.com/jsref/jsref_join.asp
For your code use Arun P Johny's solutions 对于您的代码使用Arun P Johny的解决方案
alert(data.join(' '));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.