[英]Having issues Looping over simple JSON array
When I loop over the ajax array, it is returning the index and value incorrectly. 当我遍历ajax数组时,它错误地返回了索引和值。
$.ajax({
url : '/ajax/deal_start_times/'+$pid,
success : function(data){
var tmp = "";
$.each(data, function(index, value) {
tmp = tmp + index + '|' + value + "<br />";
});
alert(tmp);
}
});
The ajax call to: '/ajax/deal_start_times/'+$pid' returns: 对'/ ajax / deal_start_times /'+ $ pid'的ajax调用返回:
["02:00","03:00","05:00","08:00","10:00","12:00"]
Here is the alert output: 这是警报输出:
0| 0 |
1| 1 |
2| 2 |
3| 3 |
4| 4 |
5| 5 |
6|[ 6 | [
7|" 7 |”
8|0 8 | 0
9|2 9 | 2
10|: 10 |:
11|0 11 | 0
12|0 12 | 0
13|" 13 |”
14|, 14 |,
15|" 15 |”
16|0 16 | 0
17|2 17 | 2
18|: 18 |:
19|0 19 | 0
20|0 20 | 0
21|" 21 |”
22|, 22 |,
23|" 23 |”
24|0 24 | 0
25|2 25 | 2
26|: 26 |:
27|0 27 | 0
28|0 28 | 0
29|" 29 |”
30|, 30 |,
31|" 31 |”
32|0 32 | 0
33|2 33 | 2
34|: 34 |:
35|0 35 | 0
36|0 36 | 0
37|" 37 |”
38|, 38 |,
39|" 39 |”
40|0 40 | 0
41|2 41 | 2
42|: 42 |:
43|0 43 | 0
44|0 44 | 0
45|" 45 |”
46|, 46 |,
47|" 47 |”
48|0 48 | 0
49|2 49 | 2
50|: 50 |:
51|0 51 | 0
52|0 52 | 0
53|" 53 |”
54|] 54 |]
What am I doing wrong? 我究竟做错了什么?
将dataType: 'json'
添加到您的AJAX请求中,否则data
只是一个字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.