<html>
<head>
<script type="text/javascript" src="getRows.js"></script>
<head>
<body onLoad="getRows()">
<div id="rows"></div>
</body>
</html>
JAVASCRIPT
function getRows(){
if(xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
xmlHttp.open('GET', 'getRows.php', true);
xmlHttp.onreadystatechange = getRowsResponse;
xmlHttp.send(null);
}
}
function getRowsResponse(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var xmlResponse = xmlHttp.responseXML;
xmlRoot = xmlResponse.documentElement;
RowArray = xmlRoot.getElementsByTagName('Rows1');
document.getElementById('rows').innerHTML = RowArray.item(0).firstChild.data;
}
}
}
PHP CODE
Code: Select all
<?php
ini_set('session.cache_limiter','private');
session_start();
$mysqli = new mysqli('localhost', 'root', '', 'myDB');
header('Content-Type: text/xml');
$dom = new DOMDocument();
$response = $dom->createElement('response');
$dom->appendChild($response);
$RowResult = $mysqli->query("SELECT * FROM table");
$RowNum = $mysqli->affected_rows;
$RowText = $dom->createTextNode($RowNum);
$RowRes = $dom->createElement('Row1');
$RowRes->appendChild($RowText);
$response->appendChild($RowRes);
$xmlString = $dom->saveXML();
echo $xmlString;
$RowResult->close();
$mysqli->close();
?>