1

So I have this problem, where I have a database-client, and the way it is right now, is that when the page loads, it generates sections for every row in a database table containing a domain name, and the corresponding IP-address for it with PHP.

On top of that, I have a "additional information" -button, that loads information from a php whois -API site, which scans the corresponding address and returns all whois -information about that site (creation date, expiration date, etc.)

So I would like to change this system from a button to a instantenous system, but can't seem to be able.

I think the problem lies in the page trying to load all the scripts before it get the information

//This is the Jquery for the button press, which loads the additional information


 $(document).ready(function showresult(){
  $(".showinfo").click(function(){


        site = ($(this).closest('.row').find('li:first').text());

      $('.result').load('http://localhost/database/phpwhois-4.2.2/whois.php?query='+site+'&output=nice #result  ');
      $('.result').show();

      $('.hideinfo').show();
      $('.showinfo').hide();

          });  
  });

And then the PHP

print "<div class='row'>";
print "<li class='names'>".$row['name']."</li>";
print "<li class='add'>".$row['add']."</li>";
print "<br><br>";

print "<div class='addinfo'>
                    <button class='showinfo'>More information </button>

        <div class='result'>

        </div>

";

EDIT

So the thing I tried, that didn't work was something in the lines of

  $(document).ready(function(){
  setTimeout(showinfo, 1000);
 }


  function showinfo(){

        site = ($(this).closest('.row').find('li:first').text());

  $('.result').load('http://localhost/database/phpwhois-4.2.2/whois.php?query='+site+'&output=nice #result  ');
  $('.result').show();

  $('.hideinfo').show();
  $('.showinfo').hide();

      });  
  });
matsutus
  • 74
  • 9
  • Where is the code that you have already tried for the "instantenous system" ? – 2pha May 16 '16 at 09:41
  • Well basically the thing I tried was just taking away the need for click in $(".showinfo").click(function() and then adding a 2 second delay for the load of this function – matsutus May 16 '16 at 09:46
  • Just removing the click event listener wont work because the function within the click handler relies on `$this` to find the closest row. You should loop over the rows. I will add an answer. – 2pha May 16 '16 at 09:50

1 Answers1

2

You will need something like this:

$(document).ready(function(){
  // Find each row
  $('.row').each(function(){
    // Store the current row JQuery object so we only have to find this once (better performance).
    var currentRow = $(this);
    // get the first li text
    var site = currentRow.find('li:first').text();
    // Query whois and put it into result
    currentRow.find('div.result').load('http://localhost/database/phpwhois-4.2.2/whois.php?query='+site+'&output=nice);
  })
}); 

This code is untested.
Also...
Your lis should be enclosed by a ul or ol.

2pha
  • 9,798
  • 2
  • 29
  • 43
  • This works! It loads the information on page load ! Thank you very much man! :) Also, thanks for commenting your process – matsutus May 16 '16 at 10:31