Hello all.
Please could you assist me with an issue I am experiencing with jquery and php.
I have an html page which needs to populate a html table with results that are posted
to a php file.
If I call the php file by itself. It does return the data shown as expected.
Here is my jquery code :
<script type="text/javascript">
jQuery(document).ready(function(){
// First I init the datatable thingy
oTable = $('#basicTable').dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers"
});
//Onclick of a button or element with id "sx"
//fire this function
$("#sx").click(function()
{
//Get the value of an html textbox
var searchString= $("#s").val();
//var data='search='+ searchString;
var dataString=searchString;
if(searchString)
{
$.ajax(
{
type: "POST",
url: "http://localhost/cx/classes/search.php",
data:dataString,
beforeSend: function(html)
{
$("#basicTable").html('');
$("#basicTable").append(html);
},
success: function(html)
{
$("#basicTable").show();
$("#basicTable").append(html);
alert('Success entered');
}
});
}
return false;
});
});
</script>
here is the html body table :
<table class="display" id="basictable">
<thead>
<tr>
<th>Document Name</th>
<th>Browser</th>
<th>Platform(s)</th>
<th>Engine version</th>
<th>CSS grade</th>
</tr>
</thead>
<tbody>
<tr class="gradeX">
<td>Trident</td>
<td>Internet
Explorer 4.0</td>
<td>Win 95+</td>
<td class="center">4</td>
<td class="center">X</td>
</tr>
</tbody>
</table>
Here is my php code :
contents of connect.php
<?php
//Database Connection DSN
$link = mysql_connect("localhost", "username", "password") or die (mysql_error());
mysql_select_db("database",$link) or die (mysql_error());
?>
search.php code
<?php
include ('connect.php');
//RUN DEFAULT SQL QUERY
$strQuery = "SELECT * from _nodeLinks";
$result = mysql_query($strQuery) or die(mysql_error());
print "<table class=\"display\" id=\"basictable\">";
if ($result) //Does the query return results ??
{
print "<thead><tr><th>Document Name</th><th>Browser</th><th>Platform(s)</th><th>Engine version</th><th>CSS grade</th></tr></thead><tbody>";
while($row = mysql_fetch_array($result))
{
print "<tr class=\"gradeX\"><td>". $row['NODE_NAME'] ."</td><td>Internet Explorer 4.0</td><td>Win 95+</td><td class=\"center\">4</td><td class=\"center\">X</td></tr>";
}
print "</tbody></table>";
}
else
{
print "<script language=\"JavaScript\" type=\"text\/javascript\">alert('No Results');</script>";
}
?>
Yet when I do the post, my html5 table returns with now rows.