How can I retrieve a response page from an ajax object ?

Discussion in 'Joomla' started by Ninja2112, Dec 7, 2011.

  1. #1
    Hello, volks...

    I haven't suceed to open my "test page" yet. I'm using Joomla 1.5...Here goes the details:
    In the body of my article there's a form which should connect my mySql DB. My template
    is configured to receive contents inside the central <div>.
    The submit of my form calls openPage1("TESTE1.php")
    Here's the function :

    <script type="text/javascript">

    function openPage1(value) {
    var url = value;
    var ajax = new XMLHttpRequest();
    var conv = document.getElementById("slcConv");
    var financ = document.getElementById("slcFinanc");
    var frmContr = document.getElementById("slcFrmContr");
    var prazo = document.getElementById("slcPrazo");

    ajax.open("POST","url?$slcConv="+conv+"$slcFinanc="+financ+
    "$slcFrmContr="+frmContr+ "$slcPrazo="+prazo);


    ajax.onreadystatechange = function() {

    document.getElementById('content').innerHTML = ajax.responseText;
    alert ("ALL RIGHT");
    }
    ajax.send(null);
    }

    Piece of code from the file "TESTE1.php", which receives the parameters from the ajax object:

    <?php
    $conv = $_POST["slcConv"];
    $financ = $_POST["slcFinanc"];
    $frmContr = $_POST["slcFrmContr"];
    $prazo = $_POST["slcPrazo"];
    echo $financ;
    echo $frmContr;
    echo $prazo;
    ?>

    He presents the "ALL RIGHT" message, but returns the home content inside the central <div>, not the content from the "TESTE1.php" page.
    What's wrong ? Where can I define the "content" <div> ?
    Another thing: If I use the conditional if(ajax.readyState == 4 && ajax.status == 200) he only returns the home content, without the alert.

    Thanks
     
    Ninja2112, Dec 7, 2011 IP