0

I have a variable on a page like this:

var userdetails = "{ 'id': '1', 'username': 'me', }";

now, I wanna call a function to load those id and username in some divs like this one:

loaduser(userdetails)

I used this but didn't work

function loaduser(jsoni){

$.getJSON(jsoni, function(data) { $('#id').html(data.id); $('#username').html(data.username); } }

thank u guys ;)

1 Answer 1

1

Use jQuery.parseJSON. Your example won't work though because it is not valid JSON (valid JSON requires double instead of single quotation marks):

var userdetails = '{ "id": 1, "username": "me", }';
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.