Solved

Need to add dynamically to json parameters

Posted on 2013-11-11
1
219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

737 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