methods for transferring javascript array to JAVA array with AJAX

I'm currently facing an issue with posting an array of JavaScript elements into a Java array of Strings. Here's the situation...

The JavaScript code I have is as follows:

var quantity_arr = new Array();

for (var i=0; i< <%= cart.size() %>;i++) {
quantity_arr[i] = document.getElementsByClassName("quantity")[i].value;
}
xmlhttp.send("sum_of_order="+sum_of_order+"&credits_number="+credits_no+"&credit_card_number="+credit_card_number+"&quantity_arr="+quantity_arr);

And here is the corresponding Java code:

String[] myParams = new String[cart.size()];
String order_id = Integer.toString(temp);
String customer_id = "'"+session.getAttribute("user_id")+"'";
String date = "15/29/12";
String sum = request.getParameter("sum_of_order");
String credit_card = "'"+request.getParameter("credit_card_number")+"'";
String credits = "'"+request.getParameter("credits_number")+"'";
myParams = request.getParameterValues("quantity_arr");

All the parameters are functioning well except for the myParams array, which remains empty. Any assistance or suggestions would be greatly appreciated!

Answer №1

Give it a shot

String[]  params = request.getParameterValues("quantity_arr").split(",");

Answer №2

If you're looking for more information, check out: ()

Essentially, you can't just pass in "quantity_arr="+quantity_arr, you need to do it this way:

"quantity_arr="+quantity_arr[0]+"&quantity_arr="+quantity_arr[1]+"&quantity_arr="+quantity_arr[2]+ ...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is preventing autoboxing from happening in this situation?

Can you explain why autoboxing doesn't happen in this scenario?: int [] array = new int[]{1,3,6,2,-1,6};// if it had been Integer instead of int, would have worked. List<Integer> liston = Arrays.asList(array); Is there a specific reason for th ...

JavaScript-based tool for extracting content from Sketch file

My goal is to extract the contents of a .sketch file. I have a file named myfile.sketch. When I rename the file extension to myfile.zip and extract it in Finder, I can see the files inside. However, when I try the same process on the server using Node.js ...

Add the child's input query first and then concentrate on it

I have successfully appended a div with a child input, but I am facing an issue where the newly appended input is not getting focused when added. $(document).ready(function() { var max_fields = 10; //maximum input boxes allowed var wrapper ...

Difficulty encountered in storing information in the database

I have been developing a survey generator but I am facing an issue where everything is empty. The client enters one or many questions, along with one or many answers for each question. These inputs are sent to my database. I have successfully coded the d ...

Searching an array object inside another array object using JavaScript/AngularJS

Here is my issue: I am facing a situation where I have two Array objects as follows var array1 = [{ "id": 1, "name": "potatoe", photo="photo"}, {"id": 2, "name": "budget"}] var array2 = [{ "id": 1, "name": "potatoeModified"},{ "id": 3, "name": "UhOhA ...

Discover the name of a color using its HEX code or RGB values

Is there a way to retrieve the color name from RBG or HEX code using JavaScript or JQuery? Take for instance: Color Name RGB black #000000 white #FFFFFF red #FF0000 green #008000 ...

Implementing the rendering functionality in Vuejs 3 to activate the parent component method from its child

Is there a way to call the clicked method on app2 from within ComponentA? Let's explore how this can be achieved in the provided example. const app = Vue.createApp({}); app.component('ComponentA', { template: `<button @click="cl ...

[AWS Lambda SDK] - Executing Lambda Function - Processing Payload Response as Unit8Array - Conversion to String

Currently, I am utilizing the npm package @aws-sdk/client-lambda to invoke Lambdas. In my setup, I have two Lambdas - Lambda A and Lambda B, with Lambda A responsible for invoking Lambda B. The invocation of Lambda B from Lambda A is done through the foll ...

The script ceases to function once the page is loaded from a JSON file

I'm facing an issue on my shopping website where the items and products are loaded from a JSON file. The problem is that once the page has loaded, the script fails to work properly. If the items take a little longer to load on the page, the script doe ...

Updating data on the next page with the ID from the previous page in Ionic

In my Ionic application with a SQLite database, I need to transfer data from the "Data Form" page to the "Add More Info" page using the same ID. This data needs to be loaded on the "Add More Info" page before any controller is executed. Once on the "Add Mo ...

Generating dynamic JComboBox components

I am currently working with a JComboBox that contains numerical values: JComboBox test; String[] a = new String[5]; for (int i = 0; i < 5; i++) { a[i]=i+1 + ""; } test = new JComboBox(a); My goal is to dynamically generate multiple JCo ...

Customize your select element's background using jQuery when the content changes

Here is a select element with different options to choose from: <select class="state"> <option value="1">Done</option> <option value="2">Closed</option> <option value="2">Open</option> <option v ...

Ensure that the floated element stretches to 100% height in order to completely fill the page

I'm working on achieving a height of 100% for the left sidebar so that it fills the page regardless of the size of the "main" div. Currently, it stops at the normal page height and doesn't expand further. Is there any way to make this work as i ...

Formula for determining the slider's span

I recently created a range slider using Vue.js It has a minimum and maximum value, assumed to be percentages as it ranges from 0 to 100. My goal is to set the minimum value at $5,000 and the maximum at $200,000, However, I struggle with math and need th ...

Using Vue.js to group JSON arrays multiple times

I have a program that I utilize to import a CSV data file and then convert it into JSON format. The resulting JSON structure is as follows: { "Class": "Cultivated Mushrooms", "Type": "Shii-take", "Grade": "Medium", "LvH": "SP", "Description": " ...

What steps can I take to ensure my customized tab component can successfully pass an index to its children and effectively hide panes?

I'm currently working on developing a custom Tabs component to enhance my knowledge of React, but I seem to have hit a roadblock. The structure involves three key components that draw inspiration from Material-UI tabs: Tabs, Tab, and TabPane. Tabs.j ...

How to format line breaks and indentation for better viewing with MySQL's json.dump() method

I am currently working with code to extract and display data from my SQL database. Strangely, I have found that only one command has been successful in this process. json_string = json.dumps(location_query_1) My query pertains to the specific format in w ...

What is the best way to extract keys and values from JSON data in a Python script?

In my Python code, I am working with a variable named data which holds the following JSON value: data=['{"time":["1000","MS"],"What is your name?":["John"]}'] My goal is to extract the keys and values from this data and present them as shown be ...

Utilize AngularFire to generate a new User and invoke the factory function to showcase notifications

I recently started working with AngularJS and wanted to integrate it with AngularFire/Firebase for storing project data. I created a factory that manages notifications to be displayed in a centralized location. Here is the structure of my factory: myApp.f ...

Switch a div to a computed location

I'm having trouble getting this code to animate a div to a calculated position. Can someone please help me troubleshoot? $(document).ready(function() { var is_Clicked = false; $("#togglebutton").click(function() { if (is_Cli ...