How to prevent jQuery Mobile from making ajax calls when entering html pages dynamically

Instead of using ajax calls, I create and paste the pages into the $ .mobile.pageContainer file. Dynamically create jQuery mobile pages using jQuery templates

When I want to access a page with a hash tag (which is generated in my onReady function), jQuery mobile tries to make an ajax call. It fails. When my onReady function is called, I have to check the url and call $ .mobile.changePage () so that it displays.

var loc = window.location.href;
var loc = loc.split('#').pop();
if (loc !== "http://lift.pageforest.com/") {
    $.mobile.changePage(loc, 'pop', false, true);
}

Which is all well and good, but jQuery Mobile still made an unsuccessful ajax call, resulting in an error being output to the console, as well as a big div error shown to the user.

I tried to override the $ .mobileinit ajaxEnabled () function to false because I will never use ajax. http://jquerymobile.com/demos/1.0a3/#docs/api/globalconfig.html Unfortunately, this created a whole bunch of other problems.

Why does jQuery mobile automatically assume that I want to use ajax and I will not generate content in my own onReady function? How do I get around this?

Sent from here: http://forum.jquery.com/topic/how-to-disable-automatic-ajax-calls-when-dynamically-creating-pages

+3
source share
1 answer

Can you use event.preventDefault ();?

http://api.jquery.com/event.preventDefault/

, rel= "external" JQ , .

<a href="#mylink" class="hash-link" rel="external">Link</a>

<script>  
$('.hash-link').click(function() {

   var loc = window.location.href;
   var loc = loc.split('#').pop();
   if (loc !== "http://lift.pageforest.com/") {
        $.mobile.changePage(loc, 'pop', false, true);
    }

});
</script>
0

Source: https://habr.com/ru/post/1794825/


All Articles