我有一个ajax电话,可在该网址上获得网站的配色方案。 (我们有很多采用不同方案的客户端,这就是为什么我们必须将它们存储在数据库中的原因)。

我要实现的是等待ajax调用完成,然后再加载页面上的所有内容。我知道会有大约1-2秒的小延迟,但这是真正隐藏更改文本颜色和背景颜色的过程的唯一方法。

谢谢!

最佳答案

您可以在加载期间隐藏主体,并在完成ajax请求后显示该主体,如以下代码所示:

<html>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
    </head>
    <body>
        <script>
            document.getElementsByTagName('body')[0].setAttribute("style", "display: none"); //hide the body
        </script>
        <h1><a>Test</a></div>
        <script>
            $( document ).ready(function() {
                $.ajax({
                  url: "your ajax url",,
                  success: function( result ) {
                    $('h1 a').css('color', 'blue'); //process result here like changing the colors of the text and background color.

                    $('body').show();
                  }
                });
            });

        </script>
    </body>
</html>

09-30 13:46
查看更多