我从jquery autocomplete插件获得这种类型的响应:
{"data":{
"events":{"id":"96","value":"Nr 1 Offline","abbrev":"image.jpg"},
"users":{"id":"9346","value":"John":"avatar.jpg"}
}
}
现在,我该如何处理这些数据?例如:
将其头像图片附加到<img>
标记;
我是jquery-ui的新手,所以一个小例子对我很有帮助。
答案 0 :(得分:1)
例如提醒一些用户的名字或将他的头像图片附加到am标签?我是jquery ui的新手,所以一个小例子对我很有帮助
警告用户名:
$data = {"data":{
"events":{"id":"96","value":"Nr 1 Offline","abbrev":"image.jpg"},
"users":{"id":"9346","value":"John", "avatar":"avatar.jpg"}
}
}//Note please I've added an "avatar" key to your $data
alert($data.data.users.value);
将他的头像图片附加到img标签:
$data = {"data":{
"events":{"id":"96","value":"Nr 1 Offline","abbrev":"image.jpg"},
"users":{"id":"9346","value":"John", "avatar":"avatar.jpg"}
}
}; //Note please I've added an "avatar" key to your $data
$("#your-image-id").attr("src", $data.data.users.avatar);
我希望它有所帮助。干杯