python django框架ajax异步交互时(判断账号或昵称唯一)阻止form表单提交简便方式
2018-10-30 16:55
357 查看
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <script src="/static/js/jquery-3.3.1.js/" type="text/javascript"></script> <script src="/static/js/jquery.cookie.js" type="text/javascript"></script> <script> $(document).ready(function () { //鼠标离开输入框时判断合同编号是否重复 ischeck = false $('#con_num').blur(function () { contractnum = $('#con_num').val() $.ajax({ async: true, url: '/checknum/', type: 'POST', data: 'contractnums=' + contractnum, headers: { 'X-CSRFToken': $.cookie('csrftoken') }, success: function (data) { if (data.length == 6) { $('#sp_hint').html(data) $('#con_num').css('border', '1px solid yellow') ischeck = false // alert(ischeck) } else { ischeck = true // alert(ischeck) } } }) return ischeck }) $('#add_form').submit(function () { // alert(ischeck) if (ischeck) { return true } else { return false } }) }) </script> </head> <body> {% extends 'main.html' %} {% block page1 %} <div class="divs"> <form action="/addcontract/" method="POST" id="add_form"> {% csrf_token %} <p id="add_p">添加合同信息</p> <span class="sp1">合同名称</span>:<input type="text" name="contract_name" required><br> <span class="sp1">合同编号</span>:<input type="text" name="contract_number" required id="con_num"><span id="sp_hint"></span><br> 合同签订时间:<input type="date" name="Contract_signing_time" required><br> <span class="sp1">合同金额</span>:<input type="number" name="contract_amount" class="conamout"><br> <button type="submit" class="sub">提交</button> </form> </div> {% endblock %} </body> </html>
相关文章推荐
- jquery多选择动态参数的使用以及ajax异步请求中提交整个form表单中serializeArray()的使用以及后台值得获取方式
- python Django框架实现自定义表单提交
- 使用AJAX异步提交表单的几种方式
- jquery的ajax提交form表单方式总结
- form表单提交转为ajax方式提交
- Jquery通过Ajax方式来提交Form表单的具体实现
- ajax异步、同步问题,KindEditor ajax提交内容,ajax提交form表单 解决按两次的问题
- django(7)modelform操作及验证、ajax操作普通表单数据提交、文件上传、富文本框基本使用
- servlet3.0以上form表单提交(ajax异步提交)
- ajax阻止form表单提交
- ajax请求下载Stream形式的文件,需要使用form表单提交的方式
- form表单提交转为ajax方式提交
- Jquery通过Ajax方式来提交Form表单的具体实现
- ajax异步、同步问题,KindEditor ajax提交内容,ajax提交form表单
- python Django框架实现自定义表单提交
- jQuery Form Plugin:AJAX方式提交表单的完全方案
- jquery的ajax提交form表单方式总结
- ajax,异步提交form表单,从后台返回值到前端
- TP 框架 ajax[利用异步提交表单]
- ajax 异步提交form表单