django通过ajax发起请求返回JSON格式的数据,djangojson,这是python,dja
django通过ajax发起请求返回JSON格式的数据,djangojson,这是python,dja
这是python,django handler代码:
def checkemail(request): user = None if request.POST.has_key('email'): useremail = request.POST['email'] result = {} user = User.objects.filter(useremail__iexact = useremail) if user: result = "1" result = simplejson.dumps(result) else: result = "0" result = simplejson.dumps(result) return HttpResponse(result, mimetype='application/javascript')
这是AJAX部分
if(valid_email($('#reg-for-email').val())){ var email = $('#reg-for-email').val(); //这里把用户输入的EMAIL地址提交到后台数据库中去验证是否已存在。 $.ajax({ type:"POST" , url:"/reg/checkemail", data:"email=" + email , cache: false, success: function(result){ if (result==1) { $("#reg-for-email-msg").removeClass("g-hide"); $('#reg-for-email-msg').removeClass("msg-isok").addClass("msg-error").html("该邮箱已存在!"); eok = true; } else { $("#reg-for-email-msg").addClass("g-hide"); eok = false; } } }) }
URL的配置是:
url(r'^reg/checkemail/', 'reg.views.checkemail', name='ce'),
相关内容
- python使用sched模块周期性抓取网页内容,pythonsched,使用
- python与计算物理:实现数值积分的Simpson方法,pythonsi
- python使用pyPdf裁切pdf文件,,This recipe
- python 批量加水印,python加水印,.py 放到 图片文件夹
- 使用compileall来预编译python代码,compileallpython,python中有
- python读取文件同时输出行号和内容,,file = open(
- Python实现二分查找(二分查询),python二分,本来想自己
- python字符串和整形的相互转换,python字符串整形,print
- AzDG可逆加密演算法 for Python,azdgpython,花了二天的時間
- 一个python编写的用于搜索文件并进行内容替换的类,
评论关闭