Solved

Rest service Parameters

Posted on 2012-12-30
3
445 Views
Last Modified: 2013-11-19
I need to construct and concatenate a dynamic parameter string for a json restservice if I have one value in the parameter it looks like:
var A = localStorage.getItem('account');
return '{"account":"' + A + '"}'
This works and produces the value:      {"account":"systems"}
I need to pass another parameter in the same string but am struggling with how to achieve this, the string should end up looking like:
{"account":"systems" , “password”:”abc123”}
I have
var A = localStorage.getItem('account');
var P = localStorage.getItem('password');

What is the correct syntax to construct the string?
0
Comment
Question by:JoeBo747
[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
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 38731251
Shouldn't it be:

var A = localStorage.getItem('account');
var P = localStorage.getItem('password');

return '{"account":"' + A + '", "password":"' + P + '"}';

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38731254
Perhaps it would be easier if you used some sort of templating. For example:

return '{"account":"#account#", "password":"#password#"}'.replace("#account#", A).replace("#password#", P);

Open in new window

0
 
LVL 1

Author Closing Comment

by:JoeBo747
ID: 38731295
Hi  Kaufmed,

I am fairly new to jquery and could not quite work out the correct syntax your example is exactly what I needed.

Thanks,
Joe
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
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 how to dynamically set the form action using jQuery.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

624 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