开发者

using jquery to load json

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:

lo开发者_JAVA百科aduser(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 ;)


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", }';
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜