Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery: Confirm box loops on every page refresh
    primarykey
    data
    text
    <p>I am looping through an array of data with each having there own delete button with <code>class="delete_thereid"</code>. when the page loads the delete button works fine.. now after the page loads again <code>(start_timer())</code> and I try to delete a different record, the native js confirmation box pops up two times.. actually the popup increments each time the page gets refreshed. I really have been at trying to find a solution for this for a few days now with out a success. Here is my code.</p> <pre><code>var refreshSpeed = 8000; var intValID = 0; function get_post () { $.ajax ({ url: "postComments.php", type: "post", cache: false, dataType: "json", data: {type: "getComments"}, success: function (d) { var c = []; var r = []; v ar cp = []; //Check for new post, update page. $(d.results.com).each (function (k, v) { if ($("#showComments").find ("div#"+$(v).attr ("id")).length == 0) { cp.push (v); } c.push ($(v).attr ("id")); if ($.inArray ($(v).attr ("id"), c_hashid) == -1) { c_hashid.push ($(v).attr ("id")); } }); $("#showComments").prepend (cp).fadeIn ("slow"); remove_deleted (c_hashid, c); //remove post remove_deleted (r_hashid, r); //remove replies deletePost (); start_timer (); //optionBttn (); return false; } }); } function remove_deleted (ids, r) { $.each (ids, function (k, v){ if ($.inArray (v, r) == -1) { $("#showComments").find ("div#"+v).slideUp ("slow"); } }); } function confirmDelete () { if (confirm ("Are you sure you wish to delete this post?")) { return true; } return false; } function deletePost () { $("[class^=delete]").each (function () { $(this).on("click", function (e) { e.preventDefault (); //stop_timer (); if (confirmDelete ()) { $(this).die ("click"); //test $(this).unbind ().click(); //test //e.stopPropagation(); //start_timer (); } }); }); } function start_timer () { intValID = setTimeout (function () { get_post (); }, refreshSpeed); } function stop_timer () { clearTimeout (intValID); } $(document).ready (function () { $("#cbutton").attr("disabled", "disabled"); $(document).mouseup (function (e) { if ($("#layerOne").has (e.target).length === 0) { $("div[id^=replybox]").fadeOut ("fast"); } }); get_post (); textAreaAnim (); play_video (); }); </code></pre> <p>the function that is making the call is deletePost from get_post, you can see what its doing <a href="http://xlordt.linuxsecured.net/~xlordt/mfwall/" rel="nofollow">here</a></p> <p><strong>EDIT</strong></p> <p>After all this time!!! and all I had to do was</p> <pre><code>$("[class^=delete]").on ("click", function (e) { if (confirmDelete ()) { e.stopImmediatePropagation () //&lt;----this!!! this is all I needed //dorestofstuff (); } }); </code></pre> <p>No more incremented confirmation box on each page load. stopImmediatePropagation () is magical! </p>
    singulars
    1. This table or related slice is empty.
    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.
    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