Note that there are some explanatory texts on larger screens.

plurals
  1. POUnexpected multiple instance creation in jstree delegate
    primarykey
    data
    text
    <pre><code>var json_string=$.parseJSON(document.getElementById("json_db").innerHTML); $(function () { $("#folder_tree").jstree({ contextmenu: {items: customMenu}, "json_data" : {data:json_string}, "plugins" : [ "themes", "json_data", "ui", "contextmenu" ], }); }); function customMenu(node) { var items = { }; } $('#folder_tree').delegate('a', 'contextmenu', function (e) { idn = $(this).parent().attr("id"); if(idn) pool_control(idn,e); //sendMsg(idn) }); </code></pre> <p>Hi, I'm getting something really weird in jsTree. The above code shows tree creation and delegating the right click event. sendMsg(idn) sends an AJAX request to another page. pool_control(idn,e) uses the event to show a form next to the clicked node. After the form is filled, it calls sendMsg.</p> <p>The script works perfectly when I call sendMsg directly in the delegated event handler(instead of pool_control). However, when I call it through pool_control, this happens: Each pool_control is called, the no. of Ajax requests sent increases by one. The contents of the request appears to be the same, but I have no idea why the no. of ajax requests increases. This doesn't happen when I call sendMsg directly.</p> <p>What's happening? How do I fix this?</p> <p>pool_control and sendMsg:</p> <pre><code>function pool_control(id,ev) { $("#pool_count").css("left",ev.pageX); $("#pool_count").css("top",ev.pageY); $("#pool_count").css("visibility","visible"); $("#poolbutton").click(function() { $('#pool_count').css('visibility','hidden'); sendMsg(id); }); $("#poolcancel").click(function() { $('#pool_count').css('visibility','hidden'); }); } function sendMsg(a,ev) { $('#pool_count').css('visibility','hidden'); var factid = $("#factid").val(); var floor = $("#floor").val(); var ceiling = $("#ceiling").val(); var pool_count = $('#poolsize').val(); var userid = document.getElementById("userid").innerHTML; $.ajax( { type: "POST", url: "generator.php", data: {what:a,name:factid,author:userid,floor:floor,ceiling:ceiling,pool_count:pool_count}, async: false, cache: false, timeout:50000, }); } </code></pre> <p>This is a long-polling webpage. sendMsg sends a user-made change in the tree and doesn't care about the response. Another function waitForMsg is the long-polling ajax request. When it sees the change in db due to sendMsg, it calls the jstree() function again to remake the tree. When I make a change in the tree, sendMsg sends 1 request first time, 2 requests seconds time, 3 requests third time, so on. I'm pretty sure nothing's wrong in that function, but here it is, just in case</p> <pre><code>function waitForMsg() { var lastupdate = document.getElementById("lastupdate").innerHTML; var msg; $.ajax({ type: "POST", url: "oracle.php", data: {lastupdate:lastupdate}, async: true, cache: false, timeout:20000, success: function(data) { msg = data.split("@"); document.getElementById("lastupdate").innerHTML=msg[0]; document.getElementById("json_db").innerHTML=msg[1]; initPage(); //a &lt;body onready&gt; function which creates the tree again setTimeout('waitForMsg()', 200 ); }, error: function(XMLHttpRequest, textStatus, errorThrown){ setTimeout('waitForMsg()', 1000); } }); } </code></pre>
    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.
    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