hide/toggle not working reliably
I have the following code, that for some strange reason will not execute the toggle code (near the bottom) every time through, and it seems to work on the second click. Does anyone see an issue with my code that might be responsible for this? It's my belief that there is an issue with the way the file is being served, but I don't see how that makes sense. Also setTImeout doesn't work as expected. I would expect it to not do anything for 3 seconds, but it starts making AJAX requests immediately. Any insight is appreciated.
- $('#bayes-load').click(function(){
- var modelString = '';
- modelString = dataSource + '#';
- modelString += model + ':Load'
- console.log(modelString);
- $.ajax({
- type: 'POST',
- url:'analytics.jsp',
- data:{q:modelString},
- beforeSend: function(){
- $('#query-results').html('<img src="images/ajax-loader.gif"><p>Retrieving Model...</p>');
- }
- }).done(function recursionLoad(){
- var timerLoad = setTimeout(function(){
-
-
- },3000)
-
- $.ajax({
- type:'GET',
- url:'modelBN.xml',
- beforeSend: function(){$('#query-results').html('<img src="images/ajax-loader.gif"><p>Loading...</p>'); },
- timeout: 10000,
- error: function(xhr, status, error){
- recursionLoad();
- //alert("Error: " + xhr.status + " - " + error)
- },
- dataType: 'xml',
- cache:false,
- success: function(data){
- var html = '<h3>Nodes</h3><ul class="outer">';
- $(data).find('node').each(function() { // Each node
- var node = $(this);
- html += '<li>' + node.find('name').text() + '<ul class="detail">'; // Embedded list
- node.find('state').each(function() { // Each node state
- html += '<li>' + $(this).text()
-
- var prob = $(this).attr('prob');
- html += ': ' + prob;
- prob = parseFloat(prob);
- html += '<div style="height:8px; width:40px;" data-prob="' + prob*100 + '"></div>';
-
-
-
- });
- html += '</ul></li>'
- });
- html += '</ul>';
- $('#query-results').html(html). // Add to DOM
- on('click', '> ul > li', function() { // Toggle embedded display on click
- $(this).find('ul').toggle();
- $(this).toggleClass('minus');
-
-
-
- }).find('ul ul').hide(); // Hide embedded initially
- $("[data-prob]").each(function(){
- $(this).progressbar({ value: $(this).data("prob") })
- $(this).removeAttr("data-prob")
- });
-
- }//end success
-
- });//end ajax
- }); //end wrapper
-
-
-
- }); //end click