Solved

Need to add dynamically to json parameters

Posted on 2013-11-11
1
214 Views
Last Modified: 2013-11-11
I have a set of standard parameters as follows:

jsonArgs = {
                  wt:'json',
                  indent: 'on',
                  hl: 'true',
                  'hl.fl': 'content',
                  'hl.simple.pre': '<span class="highlight">',
                  'hl.simple.post': '</span>',
                  'hl.highlightMultiTerm': 'true',
                  fq: 'url:valsparwood.com',
                  'hl.fragsize': '500'};

Based on a form submission, I need to append more parameters to the above object dynamically. What is the cleanest way to do this.

Your help will be greatly appreciated.
0
Comment
Question by:Jorge Fraser
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39639430
var jsonArgs = {
                  wt:'json', 
                  indent: 'on',
                  hl: 'true',
                  'hl.fl': 'content',
                  'hl.simple.pre': '<span class="highlight">',
                  'hl.simple.post': '</span>',
                  'hl.highlightMultiTerm': 'true',
                  fq: 'url:valsparwood.com',
                  'hl.fragsize': '500'};

jsonArgs[ "parameter_name1" ] = "the value 1";
jsonArgs[ "parameter_name2" ] = "the value 2";

Open in new window


or if you've jQuery in the box :
var jsonArgs = {
                  wt:'json', 
                  indent: 'on',
                  hl: 'true',
                  'hl.fl': 'content',
                  'hl.simple.pre': '<span class="highlight">',
                  'hl.simple.post': '</span>',
                  'hl.highlightMultiTerm': 'true',
                  fq: 'url:valsparwood.com',
                  'hl.fragsize': '500'};
$.extend(jsonArgs, { parameter_name1:"the value 1", "parameter_name2":"the value 2" });

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now