Remote autocomplete not working on cached page
Hi! I'm using remote autocomplete written on the basis of this example
http://demos.jquerymobile.com/1.4.2/listview-autocomplete-remote/
- $(document).on("pagecreate", "#main-page", function(){
- $("#autocomplete").on("filterablebeforefilter", function(e, data){
- var $ul = $(this),
- $input = $( data.input ),
- value = $input.val(),
- html = "";
- $ul.html( "" );
- if( value && value.length > 2 ){
- $ul.html( "<li><div class=\'ui-loader\'><span class=\'ui-icon ui-icon-loading\'></span></div></li>" );
- $ul.listview( "refresh" );
- $.ajax({
- url: "url hided", // I hide url for this forum :)
- dataType: "json",
- crossDomain: true,
- data: {
- q: value
- }
- })
- .then( function ( response ) {
- $.each( response, function ( i, val ) {
- html += val;
- });
- $ul.html( html );
- $ul.listview("refresh");
- $ul.trigger("updatelayout");
- });
- }
- });
- });
When I load page first time or reload - autocomplete working is fine. But when I close browser and start browser again, browser loads page from cache and autocomplete not working - no requests to server (tried different browsers, the same result). I guess problem is
pagecreate event, but I don't know how to fix it.
Please tell me how to fix this problem. Thanks.