Iterating thru an array using javascript for
This question already has an answer here:
since your passing data as parameter, you can access the data
try something like this :
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/52004.html