dqz84361326 2015-05-13 21:05 采纳率: 0%
浏览 103

在AJAX内容呈现之前加载所有JS和CSS

I need to load the JS and CSS before the Ajax page HTML render. here's the scenario:

  1. I have two files 1.PHP content below code - Basically it call the ajax :
<script>

    $('#loading_spinner').show();
    var mydata = 105;
    var post_data = "isln="+mydata;
    $.ajax({
        url: 'processpage.php',
        type: 'POST',
        data: post_data,
        dataType: 'html',
        success: function(data) {
            $('.my_update_panel').html(data);
            $('#loading_spinner').hide();
        },
        error: function() {
            alert("Something went wrong!");
        }
    });
</script>
  1. processpage.php content the PHP code , JS & CSS
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Brand Management</title>
    <link rel=stylesheet type=text/css href='css/1.css'/>
    <link rel=stylesheet type=text/css href='css/2.css'/>
    <link rel=stylesheet type=text/css href='css/3.css'/>
    <link rel=stylesheet type=text/css href='css/4.css'/>

    <script type='text/javascript' src='js/jquery-1.11.2.min.js'></script>
    <script type='text/javascript' src='js/jquery-ui.min.js'></script>
    <script type='text/javascript' src='js/scripts.js'></script>
    <script type='text/javascript' src='js/mh-overlay.js'></script>
    <script type='text/javascript' src='js/jquery.qtip.min.js'></script>
</head>


 <?php 
       echo "My PHP CODE Process";
?>

Issue: when i load the pages it first execute my PHP code and after that it load all CSS and JS. but i want to load all JS and then load PHP code output

Currently It Loads :

PHP Code Output

JS1

JS2

I want it must be:

JS1

JS2

PHP Code Output

PS: I already tried with the ajax.load() and other available answer of this site , but it couldn't work!!!

Thanks in Advance!!!

  • 写回答

1条回答 默认 最新

  • dongxiong4571 2015-05-13 21:11
    关注

    What you're asking is impossible. PHP code is executed by the server before the response, including the javascript code and css, is even sent to the client. You'll need several ajax queries to achieve what you're trying to.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分