jquery.each 用法和 json
我每个 jquery 都有一个问题。我的 jsp 文件包含以下几行:
`<script type="text/javascript" src="js/monopolyAL.js"></script>
...
<script type="text/javascript">
$(this).ready(function() {
// window.setTimeout(myTimerTask, 1000); // for a single timeout event
window.setInterval(myTimerTask, 3000); // for periodical timeout events
myTimerTask();
});
</script>
...
<table title="Player Information" id="playersDataTable">
<tr>
<td>Player's Icon</td>
<td>Player's Name</td>
<td>Player's money</td>
</tr>
<tr>
<td id="player0Icon">bla</td>
<td id="player0name">bla</td>
<td id="player0money">bla</td>
</tr>
`
等等。相关Js文件包含以下相关函数:
function myTimerTask() {
jQuery.ajax({
data: "", // no data - can be ommitted
url: "MonopolyAjaxServlet",
timeout: 2000,
error: function() {
console.log("Failed to send ajax");
},
success: function(JSONResponse) {
var players=JSONResponse.players;
var currPlayer;
jQuery.each(players, function()
{
currPlayer=this;
$("#player"+currPlayer+"name").text(currPlayer.name);
})
//"ver "+ver+" dice "+dice;
}
});
}
相关Json响应如下所示:
{
"pleyars":[{
"id":0,
"name": "mmm",
"amount":"15"
},
{
"id":1,
"name": "mmm2",
"amount":"152"
}]
}
但没有发生预期的名称更改。我非常感谢有关此问题的任何帮助。
提前致谢, 利奥尔
I'm having an issue jquery each. My jsp file includes the following lines:
`<script type="text/javascript" src="js/monopolyAL.js"></script>
...
<script type="text/javascript">
$(this).ready(function() {
// window.setTimeout(myTimerTask, 1000); // for a single timeout event
window.setInterval(myTimerTask, 3000); // for periodical timeout events
myTimerTask();
});
</script>
...
<table title="Player Information" id="playersDataTable">
<tr>
<td>Player's Icon</td>
<td>Player's Name</td>
<td>Player's money</td>
</tr>
<tr>
<td id="player0Icon">bla</td>
<td id="player0name">bla</td>
<td id="player0money">bla</td>
</tr>
`
and so on. the relevant Js file includes the following relevant function:
function myTimerTask() {
jQuery.ajax({
data: "", // no data - can be ommitted
url: "MonopolyAjaxServlet",
timeout: 2000,
error: function() {
console.log("Failed to send ajax");
},
success: function(JSONResponse) {
var players=JSONResponse.players;
var currPlayer;
jQuery.each(players, function()
{
currPlayer=this;
$("#player"+currPlayer+"name").text(currPlayer.name);
})
//"ver "+ver+" dice "+dice;
}
});
}
the relevant Json response looks like this:
{
"pleyars":[{
"id":0,
"name": "mmm",
"amount":"15"
},
{
"id":1,
"name": "mmm2",
"amount":"152"
}]
}
but the expected name change does not occur. I would really appreciate any assistance on this issue.
Thanks in advance,
Lior
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
而不是
使用
if iam 正确地回答了你的问题
instead of
use
if iam getting ur question correctly
尝试:
Try:
试试这个
Try this