Avatar of Pradip Shenolkar
Pradip Shenolkar
Flag for India asked on

How to pass javascript arrays to ajax send() method and retrieve them on jsp page ?

I have following html page:
Here I have passed url to ajax's send method and retrieved those values on jsp page.
How to pass multiple arrays instead of url to send() method, and how to retrieve those arrays on jsp ?
The code is from Expert rrz.

The html page :
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<script type="text/javascript">
function ajaxFunction(){
	var ajaxRequest; 
	var parameters="product=Mobile&location=India&year=2014 ";
	try{
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
				alert("Error!!");
				return false;
			}
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
                if (ajaxRequest.status === 200) {
                } else {
                        alert('Error: ' + ajaxRequest.status); 
                       }
			    //document.myForm.result.value = ajaxRequest.responseText;
				document.getElementById("result").value = ajaxRequest.responseText;
	    }
	}
	ajaxRequest.open("POST", "rrz_ajax.jsp", true);
	ajaxRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
	ajaxRequest.send(parameters); 
}
</script>
</head>
<body>
Click on Send button.<br/>
<input type='button' onclick="ajaxFunction();" value="Send" /><br/>
Result from server: <input type='text' id='result' size="100"/>
</body>
</html>
                                      

Open in new window


The jsp page :
<%
String product = request.getParameter("product");
String location = request.getParameter("location");
String year = request.getParameter("year");
%>

Open in new window

JavaScriptAJAXJSP

Avatar of undefined
Last Comment
Pradip Shenolkar

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Pradip Shenolkar

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy