Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Need to add dynamically to json parameters

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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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)
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 …

715 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