Mr.0 Mr.0 - 1 month ago 6
Ajax Question

How to load from a HTML File with style and without flickering screen with jQuery Mobile?

I want to load with this function (index.html) file the content from the templates/finden.html file with a style and without flickering.

$("#finden").click(function(){
$("#content").load("templates/finden.html");
$("#header_titel").html("Gerichte finden");
});


I have included jQuery and jQuery Mobile in my index.html.

<link rel="stylesheet" href="js/jquery.mobile-1.4.5.min.css">
<script src="js/jquery-1.11.3.min.js"></script>
<script src="js/jquery.mobile-1.4.5.min.js"></script>


The problem is, that I need these commands in my templates/finden.html too. But when I do that, the page is flickering, while changing. If I don't include the commands, the flickering is gone, but I don't have the jQuery Mobile style in my page anymore.

Answer
$(document).on('click', '#finden', function(){ 
    $("#content").load("templates/finden.html", function() {
        $(this).trigger("create");
        $("#header_titel").html("Gerichte finden");
    });                 
});

Works for me