php - jquery not returning markup from server -
so when user on client selects item drop downlist new div container supposed display containing results query. problem have div container pops intended none of markup containing search results query.
points of interests
data.php
<?php if(!isset($_get['name'])) die('a vitamin name required.'); require '../vitamins.php'; $pdo = new pdo('mysql:host=localhost;dbname=vitamins', 'root', 'root'); $table = new vitamins($pdo); $param = $_get['name']; $data = $table->getdata($param); ?> <div class="row"> <?php while($data): ?> <?php $i = 0; while($i < 3){ ?> <div class="column"> <h1><?php print $data['name']; ?></h1> <p>serving</p> <p><?php print $data['grams']; ?>g = <?php print $data['percentage']; ?>%</p> </div> <?$i++; }?> <br/> <?php endwhile; ?>
query method vitamins.php
<?php class vitamins { protected $db; public function __construct(pdo $db) { $this->db = $db; } public function getall() { return $this->db->query('select * vitamins'); } public function getdata($name) { $nameescaped = $this->db->quote($name); $sql = "select 'v'.'name', 'f'.'name', 'p'.'grams', 'p'.'percentage', 'i'.'path' " . "from 'vitamins' 'v' join 'percentage' 'p' on 'v'.'id' = 'p'.'vitamin_id' " . "join 'food' 'f' on 'f'.'id' = 'p'.'food_id' " . "join 'images' 'i' on 'i'.'id' = 'f'.'image_id' " . "where 'v'.'name' = {$nameescaped}"; return $this->db->query($sql); } }
script in index.php
<script> $(function() { var trans = $('.transbox'); var lower = $('.containerl'); $('.dropdown li').click(function(e) { e.preventdefault(); var name = $(e.target).html(); $.get('./vitamins/data.php', { name: name }, function(data) { console.log(data); trans.html(data); trans.show(); }); lower.hide(); console.log('clicked'); console.log(trans, lower); }); }); </script>
Comments
Post a Comment