2

I am trying to load a table dynamically in a div in a php page. I want to load the tables using buttons or links on the same page.

I tried this:

<button id="fcluns" type="button" onclick="loadpage(this.id)">FC LUNs</button>
<div id="Table"></div>
<script type="text/javascript"> 
function loadpage(clicked_id){
if (clicked_id =="fcluns"){
    $("Table").html('loadingImage.gif').load('getfcLuns.php?name=<?php $Host=$_GET['name']; echo $Host;?>');
}
}
</script>

i am generating the table from a php page getfcLuns.php where mysql queries are executed to get the details from database. And i am getting the $host in this php and passing it to the helper php to generate the table.

Any other efficient way is welcome. But I want to keep the page php based only.

6
  • 1
    You CANNOT process PHP on the client side with an onClick event...consider using Ajax Commented Jul 18, 2013 at 4:59
  • can someone share a code snippet for an ajax implementation for this scenario? Commented Jul 18, 2013 at 5:07
  • Take an hidden variable with the value as $_GET['name']; Pass this variable value also to function loadpage() and pass it in the parameter... Commented Jul 18, 2013 at 5:11
  • @Mr.Alien I don't think that is what is happening here, rather the page in question is generated using PHP. On the client side the PHP code in question would not show and would be replaced with the contents of $_GET['name']. Commented Jul 18, 2013 at 5:13
  • @Mike I guess he wants to show table on click, and than fetch the data from the db onclick event Commented Jul 18, 2013 at 5:15

2 Answers 2

3
<script src="ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"; type="text/javascript"> </script>
<button id="fcluns" type="button" onclick="loadpage(this.id)">FC LUNs</button>
<div id="Table"></div>
<script type="text/javascript"> 
function loadpage(clicked_id){
 if (clicked_id =="fcluns"){
    $("Table").load("getfcLuns.php?name=<?php $Host=$_GET['name']; echo $Host; ?>");
}
 }
 </script>

This above script Worked.

Sign up to request clarification or add additional context in comments.

Comments

2

Try

$("#Table").css({'background-image':'loadingImage.gif'}).load(
    'getfcLuns.php?name=<?php echo $_GET[name];?>',
    function() {
        $(this).css({'background-image':'none'});
    }
);

Read the Documentation http://api.jquery.com/load/

2 Comments

Worked with this :<script src="ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"> </script>
@Tirtha Pratim Bhattacharjee please add it into your answer part and make accept, it will helpful to the others

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.