Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery mobile .click firing multiple times on new page visit
    primarykey
    data
    text
    <p>So I am using Jquery mobile with great success except for one issue. Now every time a dynamic content page is navigated to by a user no matter what content displays, there is always a button at the bottom that when clicked emails the content to the address specified; works great. Now the first time a page is loaded, the click fires the event once. On the second visit its fired twice, third 3 times, etc. you get the point. I've scoured the net and implement every fix I could come across, such as using "pagecreate" instead of "pageinit", binding, unbinding, removing the div, turning off caching in the DOM but nothing works. The only success I've had is using <code>.one()</code> on the click but it needs to be fired if clicked again. Here is the structure. I have to <code>.js</code> files that load each with this to start </p> <pre><code>$( "#page" ).live( "pageinit", function() { </code></pre> <p>Now I had the email function and other stuff in one file, but it makes it easier to separate them and I heard it does not matter. Now, here is the email function called in the <code>pageinit</code></p> <pre><code>$('.eb').live('click', function() { var id = $('.eb').attr('id'); var to = $('#recipient').val(); var message = $('#email').html(); var atpos = to.indexOf("@"); var dotpos = to.lastIndexOf("."); if (atpos &lt; 1 || dotpos &lt; atpos + 2 || dotpos + 2 &gt;= to.length) { alert('Please enter a valid email address!'); return false; } if(to.length == 0) { alert('Please enter a valid email address!'); return false; } $.mobile.showPageLoadingMsg(); $.post('./services/service.email.php', { id: id, to: to, message: message}, function(data) { if(data.success == true) { $.mobile.hidePageLoadingMsg(); alert('Your recipe has been sent!'); $('#recipient').val(''); return true; } if(data.success == false) { if(data.fail == 1) { alert('An error has occured sending your recipe. Try again soon!'); return false; } if(data.fail == 2) { alert('Please enter a valid email address!'); } } }, 'json'); return false; }); </code></pre> <p>Everything works flawlessly except the incremental firing of the <code>.click</code> on each new page. Can anyone lead me in the right direction?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload