admin管理员组文章数量:1313347
I would like to display a message when an Ajax
function has succeeded but being new to Ajax
I am struggling
function save_pos_reasons()
{
$.ajax({
type: "POST",
url: "save_pos_reasons.php",
data: $('#add_positioning').serialize(),
success: function() {
$("#successMessage").show();
}
});
}
<div id="successMessage"> It worked </div>
At the moment this does nothing although the actual function is working
I would like to display a message when an Ajax
function has succeeded but being new to Ajax
I am struggling
function save_pos_reasons()
{
$.ajax({
type: "POST",
url: "save_pos_reasons.php",
data: $('#add_positioning').serialize(),
success: function() {
$("#successMessage").show();
}
});
}
<div id="successMessage"> It worked </div>
At the moment this does nothing although the actual function is working
Share Improve this question edited Aug 11, 2013 at 14:31 MrCode 64.5k10 gold badges92 silver badges113 bronze badges asked Aug 11, 2013 at 14:19 tatty27tatty27 1,5545 gold badges37 silver badges74 bronze badges 2-
Looks OK to me. Are you hiding
#successMessage
by default with CSS? When you say the function is working, does that mean that the success function fires or just that the ajax call fires? Maybe your ajax call is failing. – MrCode Commented Aug 11, 2013 at 14:22 - no, there is no css attributed to the message, perhpas thats where I'm going wrong? – tatty27 Commented Aug 11, 2013 at 14:23
2 Answers
Reset to default 4The message div needs to be hidden by default, otherwise .show()
will not do anything if it's already visible.
CSS:
#successMessage {
display:none;
}
Or inline:
<div id="successMessage" style="display:none;"> It worked </div>
Try this simple code . Only if the ajax is working the message will be displayed
$.ajax({
type: "POST",
url: "save_pos_reasons.php",
data: $('#add_positioning').serialize(),
success: function() {
$("#successMessage").html("It worked");
}
});
the html
<div id="successMessage"> </div>
Hope this helps. Thank you
本文标签: javascriptShow message when Ajax function succeedsStack Overflow
版权声明:本文标题:javascript - Show message when Ajax function succeeds - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741935681a2405841.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论