Wrox Programmer Forums
|
Ajax the combination of XHTML, CSS, DOM, XML, XSLT, XMLHttpRequest, and JavaScript
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Ajax section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 28th, 2007, 08:15 AM
Authorized User
 
Join Date: May 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to firebirdjohn61
Default XmlHttp Request???

Everything worked just nice and smooth...
Using book Prof. Ajax 2.
Changed code from accessing MySQL to accessing Firebird 2.0. As long as stopped at iFrames in chapter 2. The moment I converted into XHR - everything went dead. Not even respons on alert(""); Yes, I have installed the zXml.js library.

Any idea - anyone?

Best regards John

 
Old May 28th, 2007, 08:29 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

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)
 
Old May 28th, 2007, 11:12 AM
Authorized User
 
Join Date: May 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to firebirdjohn61
Default

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 &aring; 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);
}



 
Old May 28th, 2007, 11:16 AM
Authorized User
 
Join Date: May 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to firebirdjohn61
Default

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)
Had to put the code in to replies.

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 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);
}

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);

}

 
Old May 28th, 2007, 11:19 AM
Authorized User
 
Join Date: May 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to firebirdjohn61
Default

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);
}


 
Old May 28th, 2007, 11:20 AM
Authorized User
 
Join Date: May 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to firebirdjohn61
Default

<?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;

?>

 
Old May 28th, 2007, 11:24 AM
Authorized User
 
Join Date: May 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to firebirdjohn61
Default

It seems that GetCustomerData.php is not really entered. If it had been entered like it should have been. I should have a txt-file with the info from $sInfo.

 
Old May 29th, 2007, 01:58 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

So if you browse to GetCustomerData.php?id=<a valid id here> you get what you'd expect?
What browser are you using? Sometimes request methods are case-sensitive so try GET instead of get.

--

Joe (Microsoft MVP - XML)
 
Old May 30th, 2007, 02:00 PM
Authorized User
 
Join Date: May 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to firebirdjohn61
Default

It works fine with iFrames. I changed the GetCustomerData.php to only return real text as I knew it should return. Still Responsetext was blank/empty.

 
Old June 2nd, 2007, 04:12 PM
Authorized User
 
Join Date: May 2007
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to firebirdjohn61
Default

Hi joefawcett.
I found the reason for failure.. It shouldn't be any reason - as far as I can see. But for some reason I can't apply an
include statement.
 include '../functions/functions.php';
This file is not included at all. Don't ask me why. It's just so - so far.

John






Similar Threads
Thread Thread Starter Forum Replies Last Post
request forwarging & request redirection hafizmuhammadmushtaq Servlets 2 April 24th, 2008 12:42 AM
Request Post XMLHttp : Need Help Kyum BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 5 July 5th, 2007 09:51 PM
Request.Form / Request.QueryString Toran Classic ASP Databases 4 January 17th, 2007 02:23 PM
apply xsl format to an xmlhttp request darkhalf XSLT 5 September 5th, 2006 08:34 AM
request.qurystring vs. request.form Durwood Edwards Classic ASP Databases 3 June 18th, 2004 12:09 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.