mehmet cinar
mehmet cinar

Reputation: 160

jquery mobile scripts does not work after page refresh

Im using JQM and JSF. In page, after i trigger a h:commondbutton and it's action retruns string null '', page refresh and any scprits not work. i put breakpoints in ready functions and mobile pageinit functions, but none of them works. when i remove jquerymobile library it works. Any idea for this..

<script src="js/jquery-1.8.3.js"></script>
<script type="text/javascript">
  //<![CDATA[
  $(document).on('mobileinit', function() {
    $.mobile.defaultPageTransition = 'slide';
    $.mobile.hashListeningEnabled = false;
  });
  //]]>
</script>        
<script src="js/jquery.mobile-1.2.0.js"></script>



   $(document).ready(function(){
    //some codes here
});


<div data-role="page" id="page1" >
     <script type="text/javascript">

        $('#page1').live('pageinit', function() {  

     $("#getNewValuesLinkId").bind('click', function() {   
       $("#getnewValues").trigger("click");//this jsf button
       });    

  });


</div>

jsf h:commonbutton process and return null string "". page refreshes and any script does not work.

Upvotes: 1

Views: 690

Answers (2)

mehmet cinar
mehmet cinar

Reputation: 160

i have work around but don't know what is the reason of the problem.

  $(document).on('mobileinit', function() {
    $.mobile.defaultPageTransition = 'slide';
    $.mobile.hashListeningEnabled = false;
  });

this is above funksion works while page load. but my project after refresh they not work. Thefefore there is means this page does not reload again. it brings me think the ajax methods. After ajax process, any script of page are called and so the ready, pageinit, mobile init function are not called.

So i put the code below, in mobileinit seen above.

$.mobile.ajaxEnabled = false;

the solution is that

  $(document).on('mobileinit', function() {
    $.mobile.defaultPageTransition = 'slide';
    $.mobile.hashListeningEnabled = false;
    $.mobile.ajaxEnabled = false;
  });

and i again though how can this page use the ajax?

Upvotes: 0

SamJB
SamJB

Reputation: 104

I've experienced similar problems. You could try putting your Javascript code directly in script tags, i.e. not in $(document).ready or $(document).on.

E.g. NOT this:

<script>
    $(document).on('mobileinit', function() {
    $.mobile.defaultPageTransition = 'slide';
    $.mobile.hashListeningEnabled = false;
  });
</script>

But this instead (in an appropriate place):

<script>
    $.mobile.defaultPageTransition = 'slide';
    $.mobile.hashListeningEnabled = false;
</script>

Upvotes: 1

Related Questions