使用像我下面这样的数组,如何仅读取第一行的值以及从第二行开始通过另一行的循环?我在代码中包含了注释,让您了解我想要实现的目标。
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>PHP, jQuery search demo</title>
<link rel="stylesheet" type="text/css" href="my.css">
<script type="text/javascript" src="http://localhost/dev/ajax/jquery.js"></script>
<script type="text/javascript">
$(function() {
$(".errCheck").click(function() {
$.ajax({
type: "GET",
url: "test_errors.php",
dataType:"json",
cache:false,
success: function(data){
//if 1st line of array: success == True How can I do this?
//Redirect
//else
$('#errors div').empty();
$.each(data, function (loc, msg) {//start from the second array value, in this case errOne
$(loc).html(msg);
});
},
});
return false;
});
});
</script>
</head>
<body>
<div id="container">
<div id="errors">
<div id="errOne"></div>
<div id="errTwo"></div>
<div id="errThree"></div>
</div>
<input type="submit" class="errCheck" value="Check">
</div>
</body>
</html>
我的测试错误消息文件:
<?php
$errors['success'] = "false";
$errors['#errOne'] = "Enter a valid username";
$errors['#errTwo'] = "Enter a valid email";
$errors['#errThree'] = "Enter a valid password";
echo json_encode($errors);
?>