首页 > 解决方案 > 除了使用警报功能外,我如何在 ajax 中打印警报消息

问题描述

除了使用警报功能外,我如何在 ajax 中打印警报消息。

if (x.readyState == 4 && x.status == 200)
    {
        var msg=x.responseText.trim();
        if(msg=="Thank you for booking and Have a nice Journey!!!")
        {

            alert("Successfully submitted");
            window.location="home.html";
        }

    }

标签: javascripthtmlajax

解决方案


这是代码示例:

function displayAlertMessage(message) {

    var timeOut = 5
    jQuery('#messageBox').text(message).fadeIn()
    jQuery('#messageBox').css("display", "block")

    setTimeout(function() {
        jQuery('#messageBox').fadeOut()
        jQuery('#messageBox').css("display", "none")
      }, timeOut * 1000);
    }

messageBox 是您要在其中显示警报消息的 div 标签的 id。timeOut 是您希望在屏幕上保留消息的秒数。


推荐阅读