I have a working code which searches the json records and displays all the records one by one. I want to display the records based on the search term,
The working code is following:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery PHP Json Response</title>
<style type="text/css">
div
{
text-align:center;
padding:10px;
}
#msg {
width: 500px;
margin: 0px auto;
}
.members {
width: 500px ;
background-color: beige;
}
</style>
</head>
<body>
<input type="text" id="search-json-input" />
<input type="button" id="search-json-submit" value="search" />
<br/>
<br/>
<input type="button" name="next" id="next" value="NEXT" />
<br/>
<input type="button" name="previous" id="previous" value="PREV" />
<br/>
<div id="msg">
<table id="userdata" border="1">
<thead>
<th>Email</th>
<th>Sex</th>
<th>Location</th>
<th>Picture</th>
<th>audio</th>
<th>video</th>
</thead>
<tbody></tbody>
</table>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script type="text/javascript">
var users = [];
var idx = 0;
var renderRow = function (idx) {
if (idx < 0) idx = 0;
if (idx > (users.length - 1)) idx = (users.length - 1);
var user = users[idx];
var tblRow = "<tr>" + "<td>" + user.email + "</td>" + "<td>" + user.sex + "</td>" + "<td>" + user.location + "</td>" + "<td>" + "<img src=" + user.image + ">" + "</td>" + "<td>" + "<audio src=" + user.video + " controls>" + "</td>" + "<td>" + "<video src=" + user.video + " controls>" + "</td>" + "</tr>";
$('#userdata tbody').html(tblRow);
};
var url = "json.php";
$.getJSON(url, function (data) {
users = data.members;
renderRow(idx);
$('#next').click(function() {
idx++;
renderRow(idx);
});
$('#previous').click(function() {
idx--;
renderRow(idx);
});
});
</script>
</body>
</html>
The result of json.php can be seen here: http://sco7.com/components/phonegap/json.php
The created buttons have an onclick handler that:
Repeat until valid changed index
Deletes the current displayed item text, and appends the item at the updated index.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.