Jump to content

[SOLVED] Cannout output echo value with AJAX


Anzeo

Recommended Posts

Hi all,

 

I have a problem which is driving me mad. I just started on AJAX and I was able to make a simple function that shows you some text when you click on an image.

 

However, I wanted to extend my PHP-framework (based on TemplatePower) with AJAX and so I started to work on a new implementation. However, I do not receive any output anymore. I looked over my code again and again, but I can't pinpoint where I'm wrong.

 

index.php (this makes the template object and outputs it to the browser window.

include("header.php");// contains template power and the constant definitions
    
    // Setup template
    $tpl = new TemplatePower(TEMPLATE_PATH."main.tpl");
    $tpl->prepare();

    $tpl->assign("TITLE", "De Poef Online");

    $tpl->printToScreen();

 

This is the current HTML file i'm using (it's actually a .tpl filed but it's being parsed to html thanks to TemplatePower)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta http-equiv="refresh" content="{REDIRECT_DELAY};url={REDIRECT_URL}" />
        <link rel="stylesheet" href="dpo.css" />
        <title>{TITLE}</title>
        <script type="text/javaScript" src="./scripts/CalendarPopup.js"></script>
        <script type="text/javaScript" src="./scripts/dispatch.js"></script>
    </head>
    <body>
        <div id="header"><h1>De Poef Online</h1></div>
        <div id="body">
            <a href="" onclick="dispatch('test')">test</a>
            <div id="test">. ....</div>
        </div>
    </body>
</html>

This is the javascript

var xmlhttp;

function dispatch(action)
{
    xmlhttp=GetXmlHttpObject();
    if (xmlhttp==null)
    {
        alert ("Your browser does not support HTTP Requests");
        return;
    }

    var url="dispatcher.php";
    url=url+"?action="+action;
    url=url+"&sid="+Math.random();      // add a random part to make sure the server won't use a cached file
    
    xmlhttp.onreadystatechange=stateChanged;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
}

/**
*  This function is called when the state of the httprequest has changed
*/
function stateChanged()
{
    if (xmlhttp.readyState==4) {
        document.getElementById('test').innerHTML="Done";
    } else {
        document.getElementById('test').innerHTML="Loading";
    }
}

/**
*  Autodetects which XML-HTTP Object should be fetched
*/
function GetXmlHttpObject()
{
    if (window.XMLHttpRequest)
    {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        return new XMLHttpRequest();
    }
    if (window.ActiveXObject)
    {
        // code for IE6, IE5
        return new ActiveXObject("Microsoft.XMLHTTP");
    }
    return null;
}

dispatch.php contains a simple echo statement

 

EDIT: He's flashing me the right text but then he deletes it again :/

 

EDIT2: Ok my responseText seems to be empty, it's not returning anything.

also if I ad an alert in front of the innerhtml lines the output stays on the screen, otherwise it reloads -___-0

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.