当我遍历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);
}
});
ajax调用:'/ ajax / deal_start_times /'+ $ pid'返回:
["02:00","03:00","05:00","08:00","10:00","12:00"]
以下是警报输出:
0 |
1 |
2 |
3 |
4 |
5 |
6 | [
7 |“
8 | 0
9 | 2
10 |:
11 | 0
12 | 0 <登记/> 13 | “
14 |,
15 |”
16 | 0
17 | 2
18 |:
19 | 0
20 | 0
21 | “
22 |,
23 |”
24 | 0
25 | 2
26 |:
27 | 0
28 | 0
29 | “
30 |,
31 |”
32 | 0
33 | 2
34 |:
35 | 0
36 | 0
37 | “
38 |,
39 |”
40 | 0
41 | 2
42 |:
43 | 0
44 | 0
45 | “
46 |,
47 |”
48 | 0
49 | 2
50 |:
51 | 0
52 | 0
53 |“
54 |]
我做错了什么?
答案 0 :(得分:3)
将dataType: 'json'
添加到您的AJAX请求中,否则data
只是一个字符串。