4prevent default events from occurring a block a label default event occurrence method<a href="http://www.baidu.com"onclick="Modaledit ();"> Click </a>Click on the a tag above there will be two events: Modaledit and jump to Baidu home, priority high Modaledit () if you want to prevent the jump to Baidu home event occurred, need to change to the following:1add return in tag<a href="http://www.baidu.com"onclick="return Modaledit ();"> Click </a>2Event Modaledit Add return False function Modaledit () {....return false; } b prevents the submit default event occurrence method in form form5ajax+dialog box (single-table Class) Click Edit to Process step, edit button bind event A. Get all the information for the current editing class--Front End-Find Father Parent (), find the father's front two tags prevall () b. Pop-up dialog box and display the default information--Front End-Removeclass ("Hide") -val (id) #id的input输入框隐藏-Val (title) c. Click the Submit button to send the data to the background--Ajax-$.ajax ({URL:'/modal_edit_class/', type:'POST', data: {'nid': Nid,'title': Title}, Success:function () {}}) D. Background exception handling (insert database), processing dictionary JSON as a string, returning HttpResponse ()--Server-ret = {'Status': True,'msg': None}-Try{Update database operation}-returnHttpResponse (json.loads (ret)) E. Front-end receive strings, anti-JSON processing, judging and doing different operations--Ajax-success:function () {}--success, refresh current page location.reload ()--failed, display failure message-deserialization--Json.parse (string) -serialization of the front end--Json.stringify (dictionary)
[Oldboy-django] [1 Django] Block default event occurrence + Ajax + modal Edit dialog box