javascript - How to get value from ajax php (can't get) -
page 1 : index.php
script ajax
<script> function fcall(clusters) { var clusters = document.getelementbyid("clusters").value; var request = $.ajax({ type: "get", url: "chart.php", data: {clusters: clusters} }); request.done( function( msg ) { $("#page").html(msg); }); } </script>
script php
$sql = mysql_query("select * tree_hie group no_cluster asc") or die(mysql_error()); while ($data1=mysql_fetch_array($sql)) { $clusters = $data1['no_cluster']; $sql2 = mysql_query("select * tree_hie no_cluster = '$clusters'") or die(mysql_error()); while ($data2 = mysql_fetch_array($sql2)) { <input type="button" id="clusters" name="clusters" onclick="fcall(<?php $data1['no_cluster']; ?>);" value="<?php echo $clusters; ?>"> }} /* while <div id="page"> </div>
page 2 chart.php
$clusters = $_get['clusters']."tez<br>"; echo $clusters."tez";
i have code ..
my problem ..
and output link, example
cluster 1
cluster 2 ..... etc
if click button 'cluster 1', should on div page display 1 if click button 'cluster 2' should on div page display 2 ... .. if click button 'cluster 1', on div page display 1 if click button 'cluster 2' on div page display 1 , still can't value ..
may know how fixed ?
you have 2 button same id. pass event object in function call
<input type="button" id="clusters" name="clusters" onclick="fcall(event);" value="<?php echo $clusters; ?>">
and use
function fcall(event) { var clusters = event.target.value; .... }
Comments
Post a Comment