Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Processing JSP-Form using Servlet using AJAX Post method

Processing JSP-Form using Servlet using AJAX Post method

Scheduled Pinned Locked Moved Java
javahelpjavascripthtmltesting
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    khurram_shahzad
    wrote on last edited by
    #1

    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");
                } else {
                    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                    //alert("alert\_ActiveX");
                }
                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;
                    }
    	}
                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.setRe
    
    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups