1👍
Presuming you’ve got a variable called response
containing the content of the AJAX response, you want something like this:
loaded_data = json.loads(response)
for record in loaded_data:
print record["fields"]["name"]
0👍
If the return value of django view is a list then
## Lets say variable data contains your query response
data = [
{"pk": 3,
"model": "alongjs.carmodel",
"fields":
{"car": 2, "name": "city-unlimited"}},
{"pk": 4,
"model": "alongjs.carmodel",
"fields":
{"car": 2, "name": "hill-to-city"}}
]
for x in data:
print x['fields']['name']
- [Answer]-Service management using RESTful requests
- [Answer]-Test Django app using models from a second app
- [Answer]-Encoding in Django admin
- [Answer]-Object type instead of specific value from def __unicode__ showed in admin
- [Answer]-How to check object relation is populated without catching DoesNotExist
0👍
While this question has been brilliantly been answered here . I have found another way.
var to_parse = jQuery.parseJSON(data);
var temp = '';
for (var i in to_parse)
{
temp += "<option>" + to_parse[i].fields.name + "</option>";
}
alert(temp)
I have Used jQuery.parseJSON.
👤rgm
- [Answer]-CSS stylesheet not updated in browser with DJango+Apache+Firefox on VirtualBox Ubuntu Guest
Source:stackexchange.com