Quote:
quote:Originally posted by joefawcett
Well as it's working with iframes then the problem must be the way you are trying to use the XHR. Can you show a small sample of code? What development environment are you using?
--
Joe (Microsoft MVP - XML)
|
Enviroment is linux SuSE 10.1.
All needed code here.
Now I've managed to get an alert-response. Even a response from GetCustomerData.php - if the text is outside the <?php ?>. No response from echo $sInfo;
Basic frame:
mpin01get.php
<?php
printFrameHeader();
printFooter();
function printFrameHeader(){
echo <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" encoding="ISO-8859-1">
<head>
<meta name="description" content="" />
<meta name="author" content="John Jaabæk" />
<meta name="keywords" content="" />
<title>mpin01get</title>
</head>
<frameset rows="50%,50%" style="border: 2px">
<frame name="displayFrame" src="dataDisplay.php" noresize="noresize" style="border: 2px" />
<frame name="hiddenFrame" src="about
:blank" noresize="noresize" style="border: 2px" />
EOF;
}
function printFooter(){
echo "</frameset>\n</html>";
}
?>
dataDisplay.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" encoding="ISO-8859-1">
<head>
<meta name="description" content="" />
<meta name="author" content="John H. Jaabæk" />
<meta name="keywords" content="" />
<title>dataDisplay.php</title>
<script type="text/javascript" src="./zxml.
js"></script>
<script type="text/javascript">
//<![CDATA[
function requestCustomerInfo() {
var sId = document.getElementById("txtCustomerId").value;
var oXHR = zXmlHttp.createRequest();
//alert(sId);
oXHR.open("get", "GetCustomerData.php?id=" + sId, true);
oXHR.onreadystatechange = function () {
if (oXHR.readyState == 4) {
if (oXHR.status == 200 || oXHR.status == 304) {
var sText = "Responsetext = ";
sText += oXHR.responseText;
alert(sText);
displayCustomerInfo(oXHR.responseText);
} else { alert("Not getting data");
displayCustomerInfo("An error occurred: " + oXHR.statusText);
//statusText is not always accurate.
}
}
};
oXHR.send(null);
}
function displayCustomerInfo(sText) {
var divCustomerInfo = document.getElementById("divCustomerInfo");
divCustomerInfo.innerHTML = sText;
}
//]]>
</script>
</head>
<body>
<table border = "1" bgcolor = "Gainsboro">
<tr><th colspan = "4">Skriv inn ID-nummer for å hente info:</th></tr>
<tr>
<td>ID:</td>
<td><input type="text" id="txtCustomerId" value="" /></td>
</tr>
<tr>
<th colspan = "2">
<input type="button" value="Hent informasjonen" onclick="requestCustomerInfo()" />
</th>
</tr>
</table>
<div id="divCustomerInfo"></div>
</body>
</html>
GetCustomerData.php
<?php
header("Content-Type: text/plain");
//customer ID
$sID = $_GET["id"];
//variable to hold customer info
//print("\$sID = $sID<br>\n");
$sInfo = "";
filehandling ("./testfil.txt", "w", "fb_connected\n");
//database information
$testdb = 'LINUXUTVIKLING:/opt/fbdb/mpin01.fdb';
$fbuser = "SYSDBA";
$fbpw = "masterkey";
$query = "select * from person where ID=".$sID;
//$query = "select * from v_selgeravis where SID=".$sID;
include '../functions/functions.php';
$fb_connect01 = connect_fb($testdb, $fbuser,$fbpw);
print("\$fb_connect01 = $fb_connect01<br>\n");
//$sInfo = list_info2var($fb_connect01, $query);
$sInfo .= list1row($fb_connect01, $query);
filehandling ("./testfil.txt", "w", "$sInfo\n");
if ($sInfo == "") {$sInfo = "Can't get data\n");};
echo $sInfo;
?>
functions.php
function list1row($fb_connect01, $query) {
$sInfo ="";
printf("list1row: \$fb_connect01 = %d<br>\n",$fb_connect01);
if(!($result=ibase_query($fb_connect01,$query))) {
print("Unable to query table!<br>\n");
exit();
}
$row = ibase_fetch_row($result);
for($i=0;$i<ibase_num_fields($result); $i++){
$sInfo .= sprintf("$row[$i]<br />\n");
}
filehandling ("Test.txt", "w", $sInfo);
return ($sInfo);
}
function filehandling ($filename, $mode, $text) {
$myfile = fopen($filename, $mode);
fputs($myfile, "$text\n");
fclose($myfile);
}
function connect_fb($testdb, $fbuser,$fbpw) {
if (!($fb_connect = ibase_connect($testdb,$fbuser,$fbpw, 'ISO8859_1', 0, 3)))
die('Could not connect: ' . ibase_errmsg());
return($fb_connect);
}