Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery Json request and callback to html table
    primarykey
    data
    text
    <p>I habe built a cascading drop down that functions very well. when the form is submitted, the Id is passed to second script. I can´t seem to get the callback function to ...function properly. Don´t know what wrong.</p> <p>note I updated the code with the suggested changes, but something still goes wrong.</p> <p>The php:</p> <pre><code>&lt;?php if (!empty($_GET['id'])) { $id = $_GET['id']; try { $objDb = new PDO('mysql:host=localhost;dbname=blankett', 'root', 'root'); $objDb-&gt;exec('SET CHARACTER SET utf8'); $sql = "SELECT * FROM `forms` WHERE `id` = '$id'"; $statement = $objDb-&gt;prepare($sql); $list = $statement-&gt;fetchAll(PDO::FETCH_ASSOC); if (!empty($list)) { $out = array(); foreach ($list as $row ) { $out[] = '&lt;tr&gt;&lt;td&gt;&lt;a href="'.$row['link_form'].'"&gt;'.$row['name_form'].'&lt;/a&gt;&lt;/td&gt; &lt;td&gt;'.$row['date_added'].'&lt;/td&gt;&lt;/tr&gt;'; } echo json_encode(array('error' =&gt; false, 'list' =&gt; $out)); } else { echo json_encode(array('error' =&gt; true)); } } catch(PDOException $e) { echo json_encode(array('error' =&gt; true)); } }else { echo json_encode(array('error' =&gt; true)); } ?&gt; </code></pre> <p>The Jquery ajax call.</p> <pre><code>$('#blankett_form').submit(function() { var id = $(this).find('.update:last').val(); if (id == '') { alert('Välj land och region.'); //glöm inte bort att ändra beroende på land. } else { var table = '&lt;table class="table table-hover table-bordered"&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;blanketter.&lt;/th&gt;&lt;th&gt;datum tillagt.&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;&lt;/tbody&gt;&lt;/table&gt;' $('#formsubmit').empty().append(table) $ajax({ url: 'func/blankett_func2.php', data: {'id':id}, dataType: 'JSON', success: function(data) { $.each(data.list, function(index, value){ $('#formsubmit tbody').append(value); }); } }); return false }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload