Member Avatar for vijiraghs

In the following html code,

<html>
<head>
<title>Blogging</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
    var tpe;
    var islogin = 0;
    var userid;     

    function ajaxFunction()
    {
            var xmlhttp1;
            if(document.getElementById('searchtype1').checked == true)
                tpe = 1;
            else
                tpe = 2;

            if (window.XMLHttpRequest)
                xmlhttp1=new XMLHttpRequest();
            else
                xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");

            var searchvalue = document.getElementById("keyword").value;

            var url="SearchBlog?value="+escape(searchvalue) + "&type=" + escape(tpe);
            xmlhttp1.open("GET",url,true);
            xmlhttp1.onreadystatechange=callback;
            xmlhttp1.send();
    }   
    function callback()
    {
        if (xmlhttp1.readyState==4)
        {
            alert("kcj ");
        }
    }

    function def1()
    {
        document.getElementById('def').innerHTML = "";

    }   

    function default1()
    {
        document.getElementById('def').innerHTML = "Please login to create and view other blogs... <br/>If you are not a registered user, please register to get involved.";
    }

    function loginClear(x)
    {
        islogin = 1;
        userid = x;
        document.getElementById('loginlink').style.visibility = "hidden";
        document.getElementById('logoutlink').style.visibility = "visible";
        document.getElementById('prime').style.visibility = "visible";
        document.getElementById('userdisp').innerHTML = window.frames["content"].document.getElementById("name").value;
    }

    function isLogin()
    {
        //if(islogin == 1)
        //{
            def1();
            document.getElementById('content').setAttribute('src','newblog.html');
        //}
        //else
        //{
            //document.getElementById('def').innerHTML = "Please login to create a blog...";
            //document.getElementById('content').setAttribute('src','empty.html');
        //}
    }

    function checkLogin()
    {
        islogin = 0;
        document.getElementById('logoutlink').style.visibility = "hidden";
        document.getElementById('loginlink').style.visibility = "visible";
        document.getElementById('prime').style.visibility = "hidden";
        window.frames["content"].document.getElementById("loginsec").style.display = "none";
        document.getElementById('def').innerHTML = "Please login to create and view other blogs... <br/>If you are not a registered user, please register to get involved.";
    }

</script>
</head>

<body onload="default1();">
    <div id="wrap">
        <div id="header">
            <div id="topbar">
                <div id="searchbar">
                    <form method="get" name="searchform">
                        <div>
                            <input type="text" id="keyword" />
                            <span><input type="button" value=" Go " onClick="def1();ajaxFunction();"/></span>  &nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="radio" id="searchtype1"  value="1" checked="checked"/> Blog  &nbsp;
                            <input type="radio" id="searchtype2"  value="2" /> Expert
                            <span id="prime" style="visibility:hidden">

                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Welcome, 
                            <span id="userdisp"> </span>
                            </span>
                        </div>
                    </form>
                </div>
            </div>

            <div id="subnav">
                <a href="signup.html" target="content" onClick="def1();">Register</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a id="loginlink" style="visibility:visible" href="login.html" target="content" onClick="def1();">Login</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a id="logoutlink" style="visibility:hidden" href="#" onClick="checkLogin();"> Logout </a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="#" id="newbl" onClick="isLogin();"> Create a blog </a>

            </div>

            <h1 id="sitename">BLOGGER PRESS </h1>
        </div>

        <div>
            <div id="left">
                <div id="breadcrumb">
                    Blogging &raquo; Welcome
                </div>
                <br/>

                <div id="def" style="display:block; font-size:13pt;">
                </div>

                <div>    
                    <iframe name="content" id="content" width="585px" height="400px" frameborder="0"> </iframe>
                </div>
            </div>

            <div id="sidebar">
                <h2>Other</h2>
                <ul>
                    <li><a href="#">Ay, I am an actor</a></li>
                    <li><a href="#">Microsoft buys Skype </a></li>
                    <li><a href="#">Stellarium new version launched </a></li>
                    <li><a href="#">Chinese hackers hack PS2 </a></li>
                    <li><a href="#">Samsung unveils the ugly one... </a></li>
                    <li><a href="#">Who is to release the next nexus??</a></li>
                    <li><a href="#">Darth vader's avatar released</a></li>
                </ul>

                <h2>Categories</h2>
                <ul>
                    <li><a href="#">Ay, I am an actor</a></li>
                    <li><a href="#">Microsoft buys Skype </a></li>
                    <li><a href="#">Stellarium new version launched </a></li>
                    <li><a href="#">Chinese hackers hack PS2 </a></li>
                    <li><a href="#">Samsung unveils the ugly one... </a></li>
                    <li><a href="#">Who is to release the next nexus??</a></li>
                    <li><a href="#">Darth vader's avatar released</a></li>
                </ul>
            </div>

            <div class="clear">
            </div>
        </div>

        <div id="footer">
            <p>Blogging &copy; All rights Reserved</p>
        </div>
    </div>
</body>
</html>

When the user clicks on the Go button next to the search bar, it calls the ajaxFunction();
The ajaxFunction calls 'SearchBlog.java' present inside the WEB-INF folder in tomcat6.

Code for SearchBlog.java

import java.io.*;
import java.sql.*;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SearchBlog extends HttpServlet
{
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
    {
        PrintWriter out=response.getWriter();
            response.setContentType("text/html");

            out.write("hello");
    }
}

The problem is,

ajaxFunction is getting called but the alert inside the

if(xmlhttp1.readyState == 4)
is not getting executed.

For some reason, the readyState is never becoming 4.


Can anyone please help me understand why??


Thanks in advance.

xmlhttp1 is local to ajaxFunction.

callback has no knowledge of it.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.