A
A
Alexander2015-10-18 22:48:23
JavaScript
Alexander, 2015-10-18 22:48:23

How to correctly load content through load?

<body>

<div class="upload"></div>

<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easings.min.js"></script>
<script type="text/javascript" src="js/jquery.multiscroll.min.js"></script>
<script src="js/jquery.magnific-popup.min.js"></script>
<script src="js/waypoints.min.js"></script>
<script src="js/animate-css.js"></script>
<script src="js/main.js"></script>
<script type="text/javascript">
    if ($(window).width() >= 992) {
        $('div.upload').load('load.html');
    } else {
        $('div.upload').load('main.html');
    }

How it loads :
05588fe7b5fe4df0804b711e02cbf93d.png
Load.html stores simple html markup.
How will it load with alert
if ($(window).width() >= 992) {
        $('div.upload').load('load.html');
        alert('123');
    } else {
        $('div.upload').load('main.html');
    }
662021c1f6e34bc5ba86de9f66192c37.png
At first Alert pops up and then everything loads normally.
How to load load.html correctly?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vlad, 2015-10-19
@p1rat495

if ($(window).width() >= 992) {
$.ajax({
         url: "load.html",
         success: function (data) { 
           $('div.upload').html(data);
         }
});
    } else {
$.ajax({
         url: "main.html",
         success: function (data) { 
           $('div.upload').html(data);
         }
});
}

or try to see if it will load correctly, without connecting
<script type="text/javascript" src="js/jquery.multiscroll.min.js"></script>

A
Alexander Litvinenko, 2015-10-19
@edli007

Have you heard of blocking operations? Probably the rest were just ashamed to write why only beginners use the alert.

A
Alexander Latyshev, 2015-10-18
@magalex

Try like this:

$( function(){
    if ($(window).width() >= 992) {
        $('div.upload').load('load.html');
    } else {
        $('div.upload').load('main.html');
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question