Ajax content appears in HTML DIV then disapear right away for no reason?


I have a simple Ajax script that retrieves the content of a file via URL and displays it in a <div> element. Nothing fancy except for the fact that the content retrieved appears at first and then magically disappear right after?

Since this is a rather simple example here is all the code, I am left wondering after surfing probably too many web sites and PDF documents.

Some help would be welcome, thanks!
        <script type="text/javascript" language="JavaScript" src="scripts/bridge_locale.js"></script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <input type="submit" value="pull data" onclick="callAHAH('http://localhost/test.txt', 'displaydiv', 'blablabla...');" />
        <div id="displaydiv"></div>
function callAHAH(url, pageElement, callMessage) {
    //document.getElementById(pageElement).innerHTML = callMessage;
    try {
        req = new XMLHttpRequest(); //FF
    } catch (e) {
        //alert("XMLHttpRequest did not instantiate");
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP"); //IE most common
        } catch(e) {
            //alert("Msxml2.XMLHTTP did not instantiate");
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP"); //IE less common
            } catch (e) {
                //alert("Microsoft.XMLHTTP did not instantiate");
                req = false;
                //alert("Error: could not instantiate required control in bridge script");
    req.onreadystatechange = function() { responseAHAH(pageElement); };
    req.open("GET", url, true);
function responseAHAH(pageElement) {
    var output = '';
    if (req.readyState == 4) {
        if (req.status == 200) {
            output = req.responseText;
            alert("wait a minute before disapearing...???!!!");

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HonorGodSoftware EngineerCommented:
How many alert( "req.readyState=4") and alert('req.status=200") messages do you get?
deve-lopezAuthor Commented:
I actually found the solution... it was right under my eyes :-)
In the html code I changed the type of the input control from "submit" to "button":

<input type="submit" value="pull data" onclick="callAHAH...
<input type="button" value="pull data" onclick="callAHAH...

Now it works the data remain on the page and do not disappear anymore.
Taking a break away from the computer was the actual solution :-)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
When you click submit, it tries sending the form data to the server. It wasn't that the content was disappearing, it was that you were essentially "refreshing" the page each time;)
HonorGodSoftware EngineerCommented:
Thanks for the assist and the point.

Thank you more so for providing your solution.

Good luck & have a great day.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Components

From novice to tech pro — start learning today.