使用javascript for循环访问数组
这个问题在这里已经有了答案:
因为你传递的数据作为参数,你可以访问数据
尝试这样的事情:
var $errors = {};
$errors['success'] = false;
$errors['#errOne'] = "Enter a valid username";
$errors['#errTwo'] = "Enter a valid email";
$errors['#errThree'] = "Enter a valid password";
data : $errors;
success: function(data){
for (var i in data ){
console.log(i + ':' + data[i]);
}
可能你需要这个:
success: function(data){
$.each(data, function(key, value) {
alert(key + ': ' + value);
});
}
for (var key in data){
alert(key); // gives keys success, #errOne, #errTwo, #errThree
alert(data[key]); // gives values false, Enter a valid username, Enter a valid email, Enter a valid password
}
链接地址: http://www.djcxy.com/p/52003.html