Solved

Rest service Parameters

Posted on 2012-12-30
3
443 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
  • 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

740 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