Query database and send results to within w/o page refresh
Query database and send results to within w/o page refresh
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"]]}
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"]]}
This discussion has been closed.
Replies