所以我对webapps相当新,我需要向我和我的小组一起工作的端点发出GET和POST请求。 http://54.87.197.206:8080/SparkServer/admin/api/v1/listOf/accounts
我很容易为另一个端点发出GET请求, http://54.87.197.206:8080/SparkServer/admin/api/v1/listOf/users
但是当我尝试对帐户执行相同操作时,不会打印任何内容,因此在进一步检查时,我只是将帐户端点复制到JSON文件中,并查看端点提供的JSON格式。然后查看文件,这是JSON文件的样子:
[
{
"owner":null,
"accountNum":1172162121,
"balance":10000000000000,
"creationDate":null,
"type":CHECKING
},
{
"owner":Name: Tom Eater userID: 1172354496 Password: AntsAreTasty Admin: false antEatingAntEater1@gmail.com 5712342393 AntEater,
"accountNum":1171392624,
"balance":499750000,
"creationDate":null,
"type":CHECKING
},
{
"owner":Name: andy roid userID: 1716768276 Password: studio Admin: false android@gmail.com 455148 android,
"accountNum":1689835853,
"balance":150,
"creationDate":null,
"type":SAVINGS
},
{
"owner":Name: henry lopez userID: 1615704459 Password: henrylopez Admin: false h@x.com 6895 henrylopez,
"accountNum":1360787709,
"balance":150,
"creationDate":null,
"type":SAVINGS
},
{
"owner":Name: water water userID: 1357055152 Password: waterwater Admin: false g@x.com 6895 waterwater,
"accountNum":1388328287,
"balance":150,
"creationDate":null,
"type":CHECKING
},
{
"owner":Name: bob lopez userID: 1287793332 Password: boblopez Admin: false h@x.com 9865 boblopez,
"accountNum":1103883358,
"balance":1498000000000,
"creationDate":null,
"type":CHECKING
},
{
"owner":Name: Second Rate userID: 1575771782 Password: twice Admin: false numberTwo@secondrate.com 16834943534 second,
"accountNum":1745061298,
"balance":150,
"creationDate":null,
"type":SAVINGS
},
{
"owner":Name: third heard userID: 1743678273 Password: trice Admin: false we@d.com 4 third,
"accountNum":1759645352,
"balance":150,
"creationDate":null,
"type":SAVINGS
},
{
"owner":Name: fourth quad userID: 1368217803 Password: north Admin: false south@east.west 444444 fourth,
"accountNum":1535968324,
"balance":300000000000,
"creationDate":null,
"type":SAVINGS
},
{
"owner":Name: fife fife userID: 1415822540 Password: five5 Admin: false five@s.co 555 fifth,
"accountNum":1389082491,
"balance":100000000,
"creationDate":null,
"type":SAVINGS
}
]
我的问题是文件是否错误?如果没有,那么我将如何使用jQuery对此端点执行GET和POST请求。我是否必须做一些嵌套的get jquery?任何帮助将不胜感激,谢谢。
以下是我以前的代码
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function () {
$.getJSON('http://54.87.197.206:8080/SparkServer/admin/api/v1/listOf/users',function (response) {
$.each(response, function (i, item) {
$('<tr>').append(
$('<td>').text(item.id),
$('<td>').text(item.name),
$('<td>').text(item.email),
$('<td>').text(item.username),
$('<td>').text(item.password),
$('<td>').text(item.phoneNumber)).appendTo('#records_table');
// $('#records_table').append($tr);
});
});
});
</script>
</head>
<body>
<div>
<h3>List of Users</h3>
<table id="records_table" border = "2">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Username</th>
<th>Password</th>
<th>Phone Number</th>
</tr>
</thead>
<tbody id="tablebody"></tbody>
</table>
</div>
</body>
</html>
然后我用来进入帐户的代码:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script>
$(function () {
$.getJSON('accounts.json',function (response) {
$.each(response, function (i, item) {
$('<tr>').append(
$('<td>').text(item.owner),
$('<td>').text(item.accountNum),
$('<td>').text(item.balance),
$('<td>').text(item.creationDate),
$('<td>').text(item.type)).appendTo('#records_table');
// $('#records_table').append($tr);
});
});
});
</script>
</head>
<body>
<div>
<h3>List of Users</h3>
<table id="records_table" border = "2">
<thead>
<tr>
<th>Owner</th>
<th>Account Number</th>
<th>Balance</th>
<th>Creation Date</th>
<th>Type</th>
</tr>
</thead>
<tbody id="tablebody"></tbody>
</table>
</div>
</body>
</html>