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

x
?
Solved

Rest service Parameters

Posted on 2012-12-30
3
Medium Priority
?
446 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 2000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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)

721 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