Solved

Rest service Parameters

Posted on 2012-12-30
3
436 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 74

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 74

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Read about why website design really matters in today's demanding market.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
The viewer will learn how to dynamically set the form action using jQuery.

747 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

16 Experts available now in Live!

Get 1:1 Help Now