khurram.1987 0 Newbie Poster

I am trying to process data by servlet sended by jsp form using AJAX..... with 'GET' method its working okey ... but using 'POST' method to do this creating problem that

onreadystatechage

condition not exectue at

(xmlhttp.readyState==4 && xmlhttp.status==200)

.

xmlhttp.onreadystatechange=function() {
                    if (xmlhttp.readyState==4 || xmlhttp.status==200) {
                        alert("state=4 OR 200"); //for testing...
                        //document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
                        document.getElementById("TextChatHistory").value = xmlhttp.responseText;
                    }
}

i tryed to solve this too much .... but i cant .... Any one plz help me ..... THANK ...

COMPLETE PROGRAM CODE IS GIVEN BELOW,

JSP_CODE
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%--@page import="java.util.Timer.*, java.util.TimerTask.*"
    Timer timer;
--%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>

        <script type="text/javascript" >
            function AjaxFunction() {
                xmlhttp = null;
                if(window.XMLHttpRequest) {
                    xmlhttp = new XMLHttpRequest();
                    //alert("alert_Browser");
                }
                xmlhttp.onreadystatechange=function() {
                    if (xmlhttp.readyState==4 || xmlhttp.status==200) {
                        alert("state=4 OR 200"); //for testing...
                        //document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
                        document.getElementById("TextChatHistory").value = xmlhttp.responseText;
                    }
                    else {
                        alert("state not matched"); //for testing...
                        document.getElementById("myText").innerHTML = "Error may occure";
                    }
		}
                xmlhttp.open("POST", "TextChat", true);
                var Parameter_MsgSType = "msgText=" + document.getElementById("msgText").value;
                alert(Parameter_MsgSType);  //for testing...
                xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
                xmlhttp.setRequestHeader("Content-lenght", Parameter_MsgSType.lenght);
                xmlhttp.setRequestHeader("Connection", "close");
                xmlhttp.send(Parameter_MsgSType);
                alert("Ajax fuinction finished");   //for testing...
            }
        </script>

    </head>
    <body>
        <!--<h1>Hello JSP!</h1>-->
        <div id="myText"></div> <!--for testing...-->
        <form name="TextChat" method="post" action="" >
            <textarea cols="50" rows="10" readonly id="TextChatHistory" name="TextChatHistory" >TextChat History</textarea>
            <br />
            <textarea cols="50" rows="3" id="msgText" >Enter Text</textarea>
            <select name="SentToType">
                <option value="p">Presentor</option>
                <option value="h">Host</option>
                <option value="a">Attendee</option>
                <option value="l">All</option>
            </select>
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input type="submit" value="SEND" onclick="AjaxFunction()" />
        </form>
    </body>
</html>