Query database and send results to within w/o page refresh

Query database and send results to within w/o page refresh

jespardjespard Posts: 2Questions: 0Answers: 0
edited October 2011 in General
I can not figure out how to query database and send results to within w/o page refresh. I have tried a bunch of stuff. Basically, I have a button within a form that queries a MySQL db then sends the results to a section of the page. For simplicity sake, the file [get_data.php] is the result of the query in JSON.
The 3 files I am using are below...Thanks, Jesp

/***********/
[mainpage.php]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">



DataTables example

@import "demo_table.css";


function xmlhttpPost(strURL, strElt) {
var xmlHttpReq = false;
var self = this;

if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText, strElt);
}
}
self.xmlHttpReq.send(strURL);
}

function updatepage(str, str2){
//need to determine if element is in a form (if form it is handled different)
document.getElementById(str2).innerHTML = str;
}











/***********/
[load_datatable.php]



$(document).ready(function(){
$('#example').dataTable({
"bServerSide": true,
"sAjaxSource": 'get_data.php'
}); });


CountryCityLatitudeLongitude



/***********/
[get_data.php]
{"aaData":[["ad","aixas","42.4833","1.46667"],["ad","aixirivali","42.4667","1.5"],["ad","aixirivall","42.4667","1.5"]]}

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    failing to see how this is datatables related at all.
  • jespardjespard Posts: 2Questions: 0Answers: 0
    So fbas did you run the code. If you had you would see that it returns the header but the table body does not populate. The issue is somewhere within the data tables functionality. So yes it is datatables related.
This discussion has been closed.