0
 function getXmlHttpRequestObject()
            {
                var xmlHttp = false;
                if (window.XMLHttpRequest)
                {
                    return new XMLHttpRequest(); //To support the browsers IE7+, Firefox, Chrome, Opera, Safari
                }
                else if(window.ActiveXObject)
                {
                    return new ActiveXObject("Microsoft.XMLHTTP"); // For the browsers IE6, IE5 
                }
                else
                {
                    alert("Error due to old verion of browser upgrade your browser");
                }
            }

            var xmlhttp = new getXmlHttpRequestObject(); //xmlhttp holds the ajax object

            function servletPost() {
                if(xmlhttp) { 
                   var txt = document.getElementById("txtname");
                    var txtname=document.URL;
                    xmlhttp.open("POST","ServletPost",true);
                    xmlhttp.onreadystatechange = handleServletPost;
                    xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                    xmlhttp.send("txtname=" + txtname); 

                }
            }

            function handleServletPost() {
                if (xmlhttp.readyState == 4) {
                    if(xmlhttp.status == 200) {
                        document.getElementById("message").innerHTML=xmlhttp.responseText; 
                    }
                    else {
                        alert("Ajax calling error");
                    }
                }
            }

this is my code the function servletPost() is sending the data to the servlet but only the txtname is going no other value is going to the servlet how can i solve it please help

1
  • Aaaa!! Have you ever heard anything about punctuation? Commented Apr 11, 2013 at 6:56

2 Answers 2

1

Add the all the parameters in a variable and send it. ex.

var params = "txtname=" + txtname + "&name=user";
xmlhttp.send("txtname=" + txtname);
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for your answer,i am writing var params="txtname"+txtname+"txt"+txt; and getting null values in the servlet
how r you retriving values?
String url = request.getParameter("params"); this way i dont know how to retrive
0

In your code I only see that you are sending only one parameter txtname.

If you want to send more parameters then you have add "&" in between.

params = "txtname=" + txtname + "&txt=" + txt;

1 Comment

and how should i retrive params in servlet?