检索模板中的 json 值
我从一个表中查询了以下对象,然后将各种对象放入以下 objarr 中。如何在 javascript
from django.core.serializers import serialize
json = serialize("json", objarr)
logging.debug(type(json))
response_dict.update({'objarr' : (json) })
return HttpResponse(simplejson.dumps(response_dict), mimetype = 'application/javascript')
Logging.debug 中的 UI 中检索这些值给出以下内容
{'obj_arr': '[{"pk": 56, "model": "upload_info", "fields": {"emp_id": 13, "import_flag": 1, "resource": null, "feedback": "some feedabck", "hint": "test", "time": null, "created_by": 145, "access": 0, "keywords": "test1,test9", "type": 4, "error_flag": 0, }}, {"pk": 1156, "model": "upload_info", "fields": {"emp_id": 13, "import_flag": 1, "resource": null, "feedback": "some feedabck", "hint": "test", "time": null, "created_by": 145, "access": 0, "keywords": "test1,test9", "type": 4, "error_flag": 0, }}] }
在 UI 中我尝试访问 emp_id 的值,我该怎么做
function retrieve_data(formid)
{
var form = $(formid);
form.ajaxSubmit({
dataType: 'json',
success: function (data) { //Data is the rendered oject of resposne_dict
if((data)
{
alert(load_flag);
How to print emp_id,error_flag and other details here
}
}
} ) ;
}
I have the following objects queried form a table after which the various objects are put In the following objarr.How to retrieve these values in UI in javascript
from django.core.serializers import serialize
json = serialize("json", objarr)
logging.debug(type(json))
response_dict.update({'objarr' : (json) })
return HttpResponse(simplejson.dumps(response_dict), mimetype = 'application/javascript')
Logging.debug gives the following
{'obj_arr': '[{"pk": 56, "model": "upload_info", "fields": {"emp_id": 13, "import_flag": 1, "resource": null, "feedback": "some feedabck", "hint": "test", "time": null, "created_by": 145, "access": 0, "keywords": "test1,test9", "type": 4, "error_flag": 0, }}, {"pk": 1156, "model": "upload_info", "fields": {"emp_id": 13, "import_flag": 1, "resource": null, "feedback": "some feedabck", "hint": "test", "time": null, "created_by": 145, "access": 0, "keywords": "test1,test9", "type": 4, "error_flag": 0, }}] }
In the UI i try to have to access the value of emp_id ,how do i do it
function retrieve_data(formid)
{
var form = $(formid);
form.ajaxSubmit({
dataType: 'json',
success: function (data) { //Data is the rendered oject of resposne_dict
if((data)
{
alert(load_flag);
How to print emp_id,error_flag and other details here
}
}
} ) ;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还可以尝试下面的代码来实现该功能:
希望这对您有用..:)
You can also try below code to make that work:
Hope this works for you.. :)
您需要下载 json2.js 文件 并将其添加到您的应用程序
中 在响应中尝试此
操作将在变量 emp 中获取 emp_id 的值。
同样对其他人进行操作
并将它们分配到变量中...
You need to download the json2.js file and add it to your application
In the response try this
You will get the value of emp_id in the variable emp..
Similarly do for others
and assigning them in a variable...