Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Ajax
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 28th, 2007, 09:15 AM
Authorized User
 
Join Date: May 2007
Location: Oslo, , Norway.
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

Reply With Quote
  #2 (permalink)  
Old May 28th, 2007, 09:29 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #3 (permalink)  
Old May 28th, 2007, 12:12 PM
Authorized User
 
Join Date: May 2007
Location: Oslo, , Norway.
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);
}



Reply With Quote
  #4 (permalink)  
Old May 28th, 2007, 12:16 PM
Authorized User
 
Join Date: May 2007
Location: Oslo, , Norway.
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);

}

Reply With Quote
  #5 (permalink)  
Old May 28th, 2007, 12:19 PM
Authorized User
 
Join Date: May 2007
Location: Oslo, , Norway.
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);
}


Reply With Quote
  #6 (permalink)  
Old May 28th, 2007, 12:20 PM
Authorized User
 
Join Date: May 2007
Location: Oslo, , Norway.
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;

?>

Reply With Quote
  #7 (permalink)  
Old May 28th, 2007, 12:24 PM
Authorized User
 
Join Date: May 2007
Location: Oslo, , Norway.
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.

Reply With Quote
  #8 (permalink)  
Old May 29th, 2007, 02:58 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
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)
Reply With Quote
  #9 (permalink)  
Old May 30th, 2007, 03:00 PM
Authorized User
 
Join Date: May 2007
Location: Oslo, , Norway.
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.

Reply With Quote
  #10 (permalink)  
Old June 2nd, 2007, 05:12 PM
Authorized User
 
Join Date: May 2007
Location: Oslo, , Norway.
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

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
request forwarging & request redirection hafizmuhammadmushtaq Servlets 2 April 24th, 2008 01:42 AM
Request Post XMLHttp : Need Help Kyum BOOK: Professional Ajax 2nd Edition ISBN: 978-0-470-10949-6 5 July 5th, 2007 10: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 09:34 AM
request.qurystring vs. request.form Durwood Edwards Classic ASP Databases 3 June 18th, 2004 01:09 AM



All times are GMT -4. The time now is 06:11 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.