php - How to display values to modal from jquery-ajax? -


i'm using bootstrap modal , i'm stuck displaying values modal.

here html when user click view

<a data-toggle="modal" data-id="<?php echo $row33['bicycle_id']; ?>" href="#mymodal" class="buto" >view</a> 

then used jquery-ajax pass value of data-id execute query in php

 $(document).on("click",".buto", function () {  var dataid = $(this).data('id');   $.ajax({     url: 'getid.php?id=' + dataid,     type:'get',     datatype: 'json',     context: this,     success: function(values)             {                 values = $.parsejson(values);                                    $('.table-responsive #pname').html(values.name);                 $('.table-responsive #pprice').html(values.price);                 $('.table-responsive #pdescription').html(values.description);             }  }); 

});

here getid.php file

<?php     include 'includes/connection.php';     $modaldataid = $_get['id'];     $resu = mysqli_query($conn,"select * bicycle bicycle_id = $modaldataid");    while ($row7 = mysqli_fetch_assoc($resu)){       $values['name'] = $row7['name'];       $values['price'] = $row7['price'];       $values['description'] = $row7['description']; } echo json_encode($values); ?> 

then modal values should displayed

<div class="modal-body">         <div class="table-responsive" id = "div1" style = " width: 100%; margin-right: 10%;  background-color: white;">             <table id = "" align = "center" class="table table-hover table-striped demo2" style = "table-layout:fixed;">    <thead style = "">                     <tr style = "background-color: #428bca; color: white;">                         <th class="col-sm-3">bike name</th>                         <th class="col-sm-3" >srp</th>                         <th class="col-sm-3" >details</th>                      </tr>                 </thead>                 <tbody id="mytable">                     <tr style = "text-align: center;"  data-toggle="modal" data-id="" data-target="#ordermodal">                                     <td id="pname"></td>                         <td id="pprice"></td>                         <td id="pdescription"></td>                                          </tr>                 </tbody>                             </table>         </div>     </div> 

ok. let me break problem you:

the first question should ask is: ajax-success-callback function being called? , how can verify code executed? simple: create output debug code. logging simple variables alert(...) should fine. if want debug content of array better off if log console.

so try is:

$.ajax({     url: 'getid.php?id=' + dataid,     type:'get',     datatype: 'json',     context: this,     success: function(values)             {                 // not sure alerts in ajax callbacks can try it:                 alert('inside success callback');                 values = $.parsejson(values);                 // alert value:                 alert('values.name is: '+values.name);                                $('.table-responsive #pname').html(values.name);                 $('.table-responsive #pprice').html(values.price);                 $('.table-responsive #pdescription').html(values.description);                 // log values javascript console in browser                 console.log(values);             }  }); 

try , @ output.

a. don't see alert window. means success callback function never executed or have javascript error. @ javascript console in browser see if console.log(values) created output. more console.log(...) here: what console.log , how use it?

b. see alert windows. second alert goes like: 'values.name undefined'. --> php not working expected.

without being able debug code how improve it:

<?php     include 'includes/connection.php';     $modaldataid = $_get['id'];     $resu = mysqli_query($conn,"select * bicycle bicycle_id = $modaldataid");      // expect 1 row returned need no while loop:     $row7 = mysqli_fetch_assoc($resu);      // initialize values array     $values = array();      if ($row7) {        $values['name'] = $row7['name'];        $values['price'] = $row7['price'];        $values['description'] = $row7['description'];     }      echo json_encode($values); ?> 

try , come results.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -