在Ajax函数成功时显示消息

时间:2022-09-24 23:53:29

I would like to display a message when an Ajax function has succeeded but being new to Ajax I am struggling

我想在Ajax函数成功但是对Ajax不熟悉时显示一条消息我正在努力

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

目前,尽管实际功能正在发挥作用,但这没有任何作用

2 个解决方案

#1


3  

The message div needs to be hidden by default, otherwise .show() will not do anything if it's already visible.

默认情况下需要隐藏消息div,否则.show()如果已经可见则不会执行任何操作。

CSS:

#successMessage {
    display:none;
}

Or inline:

<div id="successMessage" style="display:none;"> It worked </div>

#2


0  

Try this simple code . Only if the ajax is working the message will be displayed

试试这个简单的代码。只有当ajax正在运行时,才会显示该消息

$.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

希望这可以帮助。谢谢

#1


3  

The message div needs to be hidden by default, otherwise .show() will not do anything if it's already visible.

默认情况下需要隐藏消息div,否则.show()如果已经可见则不会执行任何操作。

CSS:

#successMessage {
    display:none;
}

Or inline:

<div id="successMessage" style="display:none;"> It worked </div>

#2


0  

Try this simple code . Only if the ajax is working the message will be displayed

试试这个简单的代码。只有当ajax正在运行时,才会显示该消息

$.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

希望这可以帮助。谢谢