转自:那忘了 ,,,,,请包涵,,,,,非原创
需求问题描述:
在使用ajax时,回调函数需要接受多个参数,查询资料,得知使用json格式的数据比较好(当然也可以使用xml)。由于项目使用的是django,这就牵扯到django后端如何传输json数据。网上查找资料,得知一个比较简单的方法就是使用django自带的simplejson库。
使用方法:
django代码:
- from django.utils import simplejson
- @csrf_exempt
- def uploadify_script(request):
- json={'ret':ret,'save_name':new_name}
- HttpResponse(simplejson.dumps(json,ensure_ascii = False))
注:其中ensure_ascii = False,参数是解决传输中文乱码问题。如果json数据不包括中文,直接simplejson.dumps(json)即可
前端获取回调函数代码:
- function(response) {
- var result = eval ("(" + response + ")");
- file_name=result.save_name;
- alert(file_name);
- },
分享到:
相关推荐
window下搭建Django环境,包含:simplejson-3.8.1、Django-1.8.4;
Python 解析 JSON 的程序库。
django-filebrowser-no-grappelli django-filebrowser,用于默认的Django管理站点。 基于 v3.1(在git中之前)考虑使用基于更新版本的...通过基于pythong版本有条件地导入simplejson,此fork与Django 1.8一起使用。
使用 json 代替 django 中的 simplejson 用content_type 代替原来的 mime_type [2014-5-7] 更新到Ueditor 1.3.6 BUGfix:更新UEditor文件夹名字,避免在linux出现找不到静态文件问题 添加一种样式,besttome, ...
如果使用simplejson.loads(request.body),就不用decode() 下面是这个问题产生及解决的过程,还有一些可能的应用场景。 1、传统方式解析表单数据 之前用Django后台接收数据的时候,一直采用的是表单的形式,通过...
只需启动 Django 应用程序(Python 2.7.3、Django 1.5.1)并在浏览器中调用相应的网站即可。 这个工具是我在柏林-勃兰登堡科学与人文学院的知识库 (Wissensspeicher - WSP) 项目实习的几周期间开发的。 使用 ...
城市地图,# Django Django==1.10.6 # auth middleware ...simplejson==3.10.0 VerbalExpressions==0.0.1 shortuuid==0.4.3 uuid==1.30 maya==0.1.8 arrow==0.10.0 pendulum==0.8.0 timeago==1.0.7
物流APP WEB及服务端 依赖 simplejson django-pagination
但在python 中,我们常用的是json 的序列化,python2.7 已经包含了json package,这个也是从simplejson 基础上改变而来。这个json 包主要提供了dump,load 来实现dict 与 字符串之间的序列化与反序列化,这很方便的...
kkbloga simple blog based on django1.7 and python3Features基本博客功能(博文、分类、归档、标签)评论、留言(评论引用),gravatar支持代码高亮图片管理动态设置编辑Dependencesdjango 1.7...mpttpillowuWSGIpytz(opt...
但更欢迎指出更多的bug和需求,作者一心向学demo(一个的展示): 必要环境为了方便安装可以使用pip simplejson uwsgi CloudFlare django-cors-headers如何使用一,Docker正在研究中........... examples二,nginx +...
第 9 章 python+Django 实现 Nagios 自动化添加监控项目 第 10 章 通过 python 和 websocket 构建实时通信系统[扩展 saltstack 监控] 第 11 章 关于 B+tree (附 python 模拟代码) 第 12 章 Python 编写的 socket ...
安装$ pip install whichpkg 用法$ whichpkg simplejson/Users/matt/.virtualenvs/whichpkg/lib/python2.7/site-packages/simplejson$ whichpkg django gevent/Users/matt/.virtualenvs/whichpkg/lib/python2.7/site...
fswproject-webservice ##FSW 项目网络服务使用: 姜戈 1.5 Python 2.7 安装依赖: $ sudo pip install django$ sudo pip install simplejson$ sudo pip install djangorestframework$ sudo pip install django-...
最终,REST api可能将需要PyYAML来弥补json和simplejson中对Unicode的不足支持。 注意:在某些时候,该项目将取决于nltk。 根据发生这种情况的时间(这是一个非常业余的项目),回拨这些要求以在Python 2.7下运行...
python-simplejson-2.0.9-3.1.el6.x86_64.rpm python-six-1.5.2-1.el6.noarch.rpm python-sqlalchemy0.7-0.7.8-1.el6.x86_64.rpm python-stevedore-0.14-1.el6.noarch.rpm python-swiftclient-2.0.2-1.el6.noarch....
python-simplejson-2.0.9-3.1.el6.x86_64.rpm python-six-1.5.2-1.el6.noarch.rpm python-sqlalchemy0.7-0.7.8-1.el6.x86_64.rpm python-stevedore-0.14-1.el6.noarch.rpm python-swiftclient-2.0.2-1.el6.noarch....