473,396 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how to send javascript array to servlet using json

4
Expand|Select|Wrap|Line Numbers
  1. success : function(responseJson) {
  2.  
  3.                         var tbody = $("#Account");
  4.                         alert("JSonResponse: " + responseJson);
  5.                         $
  6.                                 .each(
  7.                                         responseJson,
  8.                                         function(index, account) { // Iterate over the JSON array.
  9.                                             var value = ATYpeMap[account.AccountTypeID];
  10.                                             $('<tr>')
  11.                                                     .appendTo(tbody)
  12.                                                     // Create HTML <tr> element, set its text content with currently iterated item and append it to the <table>.
  13.                                                     .append(
  14.                                                             $('<td>')
  15.                                                                     .text(
  16.                                                                             account.AccountNumber))
  17.                                                     // Create HTML <td> element, set its text content with id of currently iterated account and append it to the <tr>.
  18.                                                     .append(
  19.                                                             $('<td>').text(
  20.                                                                     value))
  21.  
  22.                                                     // Create HTML <td> element, set its text content with name of currently iterated account and append it to the <tr>.
  23.                                                     .append(
  24.                                                             $('<td>')
  25.                                                                     .text(
  26.                                                                             account.AccountStatus))
  27.                                                     .append($('<td style=\"display:none;\">').text(account.AccountTypeID))
  28.                                                     .append(
  29.                                                             $('<select id="Accountchange"+r+ onchange="dropDownOnChange(this)"><option value=""></option><option value="Valid">Valid</option><option value="Invalid">Invalid</option></select>'))
  30.                                             /* .append($('<button id="{account.AccountNumber}" value="ChangeAccountStatus" onclick="AccountChange(this)">ChangeAccountStatus</button>')) */;
  31.                                         });
  32.                     }
  33.                 });
  34.  
  35.     };
  36.  var item = [];
  37.     function dropDownOnChange(e) {
  38.  
  39.          var selectedValue=e.options[e.selectedIndex].value;
  40.         alert("selectedValue:" + selectedValue);
  41.           var currentRow= $(e).closest("tr");
  42.           var AccountNo= $("td:eq(0)",$(currentRow)).text(); 
  43.          alert("accountno"+AccountNo);
  44.          var AccountType =$("td:eq(1)",$(currentRow)).text();
  45.          alert("acctyp"+AccountType);
  46.          var AcctypID= $("td:eq(3)",$(currentRow)).text();
  47.          alert("accID"+AcctypID);
  48.  
  49.          var objddlvalue= {};
  50.         objddlvalue["AccountNo"] =AccountNo;
  51.         objddlvalue["AccountType"]=AccountType;
  52.         objddlvalue["Account Type_Val"]=AcctypID;
  53.         objddlvalue["AccountStatus"]=selectedValue;
  54.          item.push(objddlvalue);
  55.          console.log(item);
  56.         var jsonObj1 = JSON.stringify(item);
  57.          //jsonObj1.parseJSON();
  58.         //JSONobj= JSON.parse(jsonObj1);
  59.          console.log(jsonObj1); 
  60. }
When I click save button I want to send all dropdown chosen value and other table data to servlet. I am not been able to send to servlet .Please help me.
Dec 6 '13 #1
6 4602
Dormilich
8,658 Expert Mod 8TB
did you check what your HTTP request actually is?
Dec 6 '13 #2
ruby88
4
Yes I set as application/json to it. I am getting json value as [{ "AccountNo": "89348734", "AccountType": "Credit", "Account Type_Val": "21", "AccountStatus": "Invalid" }] Thank you.
Dec 6 '13 #3
ruby88
4
Is it the right format? How can I loop through this value in servlet?
Dec 6 '13 #4
Dormilich
8,658 Expert Mod 8TB
servlets are Java, not JavaScript.
Dec 6 '13 #5
ruby88
4
Yes I understand Dormilich.But what I am having problem is my json format form javascript. I am not been able to get correct jsonstringarray in javascript.As per above my code,I am taking values from every dropdown event change.and wanting to save those data to servlet. since my servlet could not loop through becuase of json format. Thank you.
Dec 6 '13 #6
Dormilich
8,658 Expert Mod 8TB
the JSON rersponse given hardly matches with the AJAX coding, there is accountNo vs. accountNumber, accountTypeID does not exist, etc.

additionally, if the jQuery AJAX call is not set to json, you may need to parse the response first.

PS. console.log() is way more descriptive than alert()
Dec 6 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Oleg Konovalov | last post by:
Hi, I am trying to pass a bunch of checked checkboxes (Javascript array) from page1 to the Java action class on subsequent web page (page2). (on page 1 I have a bunch of DB rows with a checkbox,...
5
by: turnitup | last post by:
Dear all, I have a JavaScript function that talks to php using ajax. It can return values from php. Up until now, I have used it to return simple values such as integers or text strings. ...
2
by: Daz | last post by:
Hi everyone. Sorry for the confusing subject, I couldn't think how best to word it. What I would like to know, is if there is an equivilant to this code, in using JSON. <script...
2
by: Garg | last post by:
Hi All, I am facing one problem if you are having any solution please tell me. I have to pass an array from javascript to servlet. for this i created one array and pass that through submitting...
5
by: placid | last post by:
Hi All, Just wondering if there is any way of sending a JavaScript array to a Python cgi script? A quick Google search didn't turn up anything useful. Any help appreciated. Cheers
0
by: panku007 | last post by:
Hi all, I have one jsp page in that page three frames are created and one of three frame, one jsp page is displaying and from that page i want to send request to servlet from one frame...
4
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i want to retrieve the values which are arrayed on...
3
by: JJ | last post by:
I am using a handler (processImage.ashx) to display an image. The image is displayed according to parameters passed in the querystring. The handerl is called via some clientside javascript. I...
2
by: David | last post by:
Hey can anyone help me convert a javascript array into a ruby array. Ive been struggling with this since friday to no avail. This is the function with the ajax.request call that is supposed to...
7
by: vinodsk101 | last post by:
Hi all, I have one doubt, can we pass a variable from javascript to servlet??? In Brief, i am getting some values in javascript through jsp and the same values i want in servlet. Ya i know i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.