Directly on the code
<script>
$ (function () {///Get all form forms in the Web page $ ("form"). each (function () {////Registration form's Commit event $ (this). Submit (Function (event) {//Blocked form registration Event.preventdefault (); Gets the URL var url = $ (this). attr ("action"); Request (URL, ' POST ', json.stringify ($ (this). SerializeObject ()), function () {alert (' 123 ');}, null);} );});}); Convert the $.ajax function to a simple interface functions request (URL, method, param, callback, fail) {//alert (param); $.ajax ({type:method,//async:false, ContentType: "Application/json;charset=utf-8", DataType: "JSON", Url:url, Data:param, Success:callback, Error:fail,}); }//convert the data inside the form form to a JSON object $.fn.serializeobject = function () {var o = {}; var a = This.serializearray (); $.each (A, function () {if (O[this.name]!== undefined) {if (!o[this.name].push) { O[this.name] = [O[this.name]]; } O[this.name].push (This.value | | ‘‘); } else {O[this.name] = This.value | | ‘‘; } }); return o; };//then converts the JSON object into a JSON string using the Json.stringify () function.
</script>
Refer to the blog for a few changes.
Through JS, modify all form forms and submit data in JSON format.