0

Is it possible to run something similar on Jquery mobile I don't want to disable ajax calls on links and buttons. Do you know a work around for this problem. Thank you very much. I spend many hours searching for answer, but nothing works for me. I use Jquery 1.8.3 and Jquery mobile 1.2.1 with css include, on PC Jquery works fine, on mobile only if I am on index page, but jquery is in header that i include with SMARTY. I work on SMARTY. I put my javascript code between {literal} tags then between tags but without success. Thank you for your answers.

SMARTY with Jquery inside:

<link href="/js/jquery.mobile-1.2.1.min.css" rel="stylesheet" type="text/css" />
<link href="/css/stylex.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="/js/jquery.mobile-1.2.1.min.js"></script>
<script type='text/javascript' src='/includes/flash_fix.js'></script> 
<!-- {popup_init src="/javascripts/overlib.js"} -->
<!--[if lt IE 7]>
   <script type="text/javascript" src="/ie_png.js"></script>
   <script type="text/javascript">
       /ie_png.fix('.png');
   </script>
<![endif]-->
{literal}
<script type="text/javascript">
$(document).bind('pageinit', function () {
   $('#nav ul').hide();
   $('#languages').hide();
   $('#menu').click(function(e){
    e.preventDefault();
    $('#nav ul').slideToggle('300');
   }); 
   $('#lang_menu').click(function(e){
    e.preventDefault();
    $('#languages').slideToggle('300');
   });
});
</script>
{/literal}
user3342042
  • 241
  • 7
  • 20
  • 1
    What "doesn't work"? `$(..)` works "fine"; it is from jQuery, not jQuery Mobile! (Also, look at the *generated* HTML output, PHP/Smarty is irrelevant except it is how the output is generated.) – user2864740 Mar 10 '14 at 18:20
  • 6
    [`$(document).on('pageinit', function () {});`](http://api.jquerymobile.com/pageinit/). If you're using jQuery Mobile, [also use its events](http://api.jquerymobile.com/category/events/). – Jonathan Lonowski Mar 10 '14 at 18:22
  • 3
    @Jonathan: You can't expect from developers to read documentation. Where would that leave us? – Felix Kling Mar 10 '14 at 18:24
  • Just as a heads up, _SMARTY_ is a PHP templating engine. PHP is ***server-side*** scripting. JavaScript is ***client-side*** scripting... – War10ck Mar 10 '14 at 18:24
  • It works fine on smarty if u put it between literal tags otherwise it is ignored. Guys I post my code in Jquery it's very simple 10 lines of code. Can you help me how to make it work in Jquery mobile. Thank you. You save my life. – user3342042 Mar 10 '14 at 18:26
  • It works but only on home page on others it is ignored with document.ready syntax, i think its ajax problem. Dunno. – user3342042 Mar 10 '14 at 18:31
  • 1
    @user3342042 jQuery Mobile's init events are a mess. You're trying to add event handlers here. Make sure you do those only once, and only when those elements exist. Otherwise, you might have to use `.on` with a parent element. Learn more about the internals of jQuery Mobile to use it effectively. – Brad Mar 10 '14 at 18:33
  • When i refresh page it works fine but if I click on link and after redirect it doesn't work tested on oper mobile emulator ? – user3342042 Mar 10 '14 at 18:42
  • Still without good result first page load jquery fine but second third doesn't listen to click function, It only hides objects so hide() works fine at the begining of my code with Jquery mobile. – user3342042 Mar 10 '14 at 18:52
  • possible duplicate of [jQuery Mobile: document ready vs page events](http://stackoverflow.com/questions/14468659/jquery-mobile-document-ready-vs-page-events) – Evan Davis Mar 10 '14 at 18:59
  • Are you using same ID for target elements in all pages? Are you using multi-page or single page? – Omar Mar 10 '14 at 20:14
  • Hi Omar, i disable ajax after jquery and before jquery mobile then I can use document.ready on all pages. – user3342042 Mar 10 '14 at 20:23
  • Ok, problem solved then. – Omar Mar 10 '14 at 20:47

0 Answers0