从javascript调用ajax函数
很抱歉,如果这个问题没有意义,我仍在努力理解ajax、JavaScript和jQuery。这是我的问题 这是我的javascript代码:从javascript调用ajax函数,javascript,jquery,ajax,json,Javascript,Jquery,Ajax,Json,很抱歉,如果这个问题没有意义,我仍在努力理解ajax、JavaScript和jQuery。这是我的问题 这是我的javascript代码: if (colorToCheck == gup("Player1")) { document.getElementById('win').innerHTML=player1+" wins"; //add ajax call to update my json file redScore += 1 } else if (colorToC
if (colorToCheck == gup("Player1")) {
document.getElementById('win').innerHTML=player1+" wins";
//add ajax call to update my json file
redScore += 1
} else if (colorToCheck == gup("Player2")) {
document.getElementById('win').innerHTML=player2+" wins";
//add ajax call to update my json file
blackScore += 1
}
所以我想从这个块调用ajax。我在网上搜索了一下,但没有得到答案。提前谢谢。非常感谢您的帮助
$.ajax({
type: "POST",
url: "home.aspx", //you can call any function you want to execute in this url
data: datastring,
success: function(msg){
alert( "This is ajax call:" + msg );
// some code to exec on success
}
});
这是一个示例ajax调用。。
如果您专门寻找JSON,请仔细阅读以下内容:
$('#win').html(colorToCheck == gup("Player1") ? player1:player2 + " wins");
if (colorToCheck == gup("Player1"))
redScore += 1
else if (colorToCheck == gup("Player2"))
blackScore += 1
$.post("update-score.php", { player: x, score: y } );
…看来你在这里有一个很好的答案。我只是想确保您知道在页面标题中包含JQuery库。如果你不想下载,你可以使用谷歌托管的图书馆版本
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
更多图书馆可在
JQuery教程
AJAX简介
博客
YouTube也是一个了解更多信息的好地方
祝你好运 查看jQuery.ajax$.ajax()有什么问题吗?您搜索了网络,但没有得到答案?整个世界都在使用ajax和jquery。到处都有教程和示例。@Ohgoghwhy感谢您的回复。。因此我可以直接在这里添加此函数$.ajax()??@Timmerz我有一个javascript代码,我想在两者之间使用ajax。。我知道javascript和ajax,但我想把两者结合起来这是我的问题我不知道怎么做无论如何谢谢你花时间哦谢谢你我不知道我们能做到再次谢谢你的回复。。