Ajax form submission
Ajax form submission serialize ()
Front-end code:
<Script src = "js/jquery-1.11.2.js"> </script>
<Script type = "text/javascript"> $ (function () {$ ('# userName, # password, # mobile '). on ('keyup', function (e) {// give # userName, # password, # mobile binds a keyup event to three elements, if (e. keyCode = 13) {// if the user presses the Enter key (the keyCode of the Return key is 13), the user clicks it. loginBtn submit button. Trigger the submit event $ ('. loginBtn '). trigger ('click') ;}}); var data =$ ("# myForm "). serialize (); $ (". loginBtn "). on ("click", function () {var data = $ ("# myForm "). serialize (); $. ajax ({url: "ajaxFormHandler. ashx ", data: data, success: function (data) {alert (data) ;}})}); </script>
Background code (common application processing program) ajaxFormHandler. ashx
Using System; using System. Collections. Generic; using System. Linq; using System. Web; namespace JqueryUI {////// AjaxFormHandler summary ///Public class ajaxFormHandler: IHttpHandler {public void ProcessRequest (HttpContext context) {context. response. contentType = "text/plain"; var userName = context. request ["userName"]; // receives the value var mySelect = context. request ["mySelect"]; var pas = context. request ["password"]; var mobile = context. request ["mobile"]; // context. response. write ("Hello World");} public bool IsReusable {get {return false ;}}}}
Zookeeper