Monday 15 February 2010

javascript - PHP variable not being passed to AJAX call? -



javascript - PHP variable not being passed to AJAX call? -

im trying php script called ajax (that in main php file). here's illustration of supposed do: http://jsfiddle.net/xfuddzen/

the html source code shows desk_box div beingness created (which in main.php). station_info div (being created in display_station.php) not there. how can prepare this? in advance

problem: divs display_stationinfo.php not beingness created using ajax call.

main.php jquery/ajax part:

<div id="map_size" align="center"> <?php //didsplay desk stations in map while($row = mysqli_fetch_assoc($desk_coord_result)){ //naming x,y values $id = $row['coordinate_id']; $x_pos = $row['x_coord']; $y_pos = $row['y_coord']; //draw box div @ x,y coord echo "<div class='desk_box' data='".$id."' style='position:absolute;left:".$x_pos."px;top:".$y_pos."px;'>id:".$id."</div>"; } //end while loop desk_coord_result ?> <script type="text/javascript"> //display station info in hidden div toggled //and phone call php script queries , returns results live $(document).ready(function() { $('.desk_box').each((function(){(this).click(function() { var id = $(this).attr("data") $("#station_info_"+id).toggle(); $.ajax({ url: 'station_info.php', data: { 'id': id }, type: 'post', datatype: 'json', success: function(json) { $("#station_info_"+id).css({'left':json.x_pos ,'top': json.y_pos}).append('<p>hello id is:'+ json.id +'</br>section:'+ json.sec_name +'</p>'); }//end success });//end ajax });//end click });//end ready </script> </div> <!-- end map_size -->

display_station.php (script want call):

<?php include 'db_conn.php'; //query show workstation/desks info db desks $station_sql = "select coordinate_id, x_coord, y_coord, section_name coordinates"; $station_result = mysqli_query($conn,$station_sql); //see if query if ($station_result === false) { die(mysqli_error()); } //display workstations info in hidden div toggled $html = ''; if($station_result->num_rows > 0){ while($row = $station_result->fetch_object()) { $id = $row->coordinate_id; $html .= "<div class='station_info_' id='station_info_$id' style='position:absolute;left:{$row->x_coord}px;top:{$row->y_coord}px;'>hello id is:$id</br>section:{$row->section_name}</br></div>"; } } else{ // no results - may want $html $html = "no result given"; } $station_result->free(); $conn->close(); echo $html; ?>

why dont filter coordinate in query? this:

$station_sql = "select coordinate_id, x_coord, y_coord, section_name coordinates coordinate_id = " . $_get['coordinate_id'];

and in jquery code:

url: 'display_stationinfo.php?coordinate_id=' + id,

javascript php jquery html ajax

No comments:

Post a Comment