fungusblacky
fungusblacky

Reputation: 35

how to make json key value pair using two var

I have two var's

var a = result.master_id;
var b = result.session_name;

i want to create a json string to pass to ajax. i tried this

var userData = {'pid':a,'session' :b};

i'm storing this userData in a sessionStorage and sending to ajax . but i'm getting pid undefined error.

is this the right way to do this?

any help is appreciated. regards, newbie

Upvotes: 0

Views: 89

Answers (1)

Hardik Ghadshi
Hardik Ghadshi

Reputation: 66

You are using the right code to store into variable. Try to console variable to identify.

Example code given below:

let result = {
master_id: 1,
session_name: "Hardik"
}

var a = result.master_id;
var b = result.session_name;

var userData = {'pid':a,'session' :b};

console.log(userData);

Upvotes: 2

Related Questions