How can I load php in a div with button onclick events in Javascript? - Stack Overflow

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

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 wele. But I want to keep the page php based only.

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 wele. But I want to keep the page php based only.

Share Improve this question edited Nov 17, 2013 at 17:16 Dan 12.8k15 gold badges51 silver badges86 bronze badges asked Jul 18, 2013 at 4:56 Tirtha Pratim BhattacharjeeTirtha Pratim Bhattacharjee 1594 silver badges14 bronze badges 6
  • 1 You CANNOT process PHP on the client side with an onClick event...consider using Ajax – Mr. Alien Commented Jul 18, 2013 at 4:59
  • can someone share a code snippet for an ajax implementation for this scenario? – Tirtha Pratim Bhattacharjee 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... – Prem Baranwal 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']. – Mike 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 – Mr. Alien Commented Jul 18, 2013 at 5:15
 |  Show 1 more ment

2 Answers 2

Reset to default 3
<script src="ajax.googleapis./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.

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./load/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745552706a4632650.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信