Solved

Need to add dynamically to json parameters

Posted on 2013-11-11
1
213 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
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 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

11 Experts available now in Live!

Get 1:1 Help Now