Link to home
Start Free TrialLog in
Avatar of JoeBo747
JoeBo747

asked on

Rest service Parameters

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?
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of JoeBo747
JoeBo747

ASKER

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