最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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/

发布评论

评论列表(0)

  1. 暂无评论