Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need to add dynamically to json parameters

Posted on 2013-11-11
1
Medium Priority
?
228 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 83

Accepted Solution

by:
leakim971 earned 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

926 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