Ajax technology brings us a good user experience. At the same time, using jquery can simplify development and improve work efficiency. Next, let's share several ajax submission methods in Jquery, for more information, see the post and get methods for ajax submitted forms in jquery. When using the get method, we can directly use the ajax serialized form $ (Form ID) serialize (); now, let's introduce two methods for submitting form data. $ Get method: The get () method is submitted through remote HTTP. The following describes two methods for submitting form data.
$ Get form submission
The get () method loads information through a remote http get request.
Format
$(selector).get(url,data,success(response,status,xhr),dataType)
Send two parameters to the test. php webpage and ignore the returned value:
$.get("test.php", { name: "John", time: "2pm" } );
Display the test. php return value (HTML or XML, depending on the return value ):
$.get("test.php", function(data){ alert("Data Loaded: " + data);});
Ajax serialized form
$.Form.serialize( NameValuePair )
Virtualize a form and set the Form Control name and value.
Parameters
NameValuePair
Required. Set a virtual form control. The parameter format is {name1 = value, name2 = value2 ,......}
Return Value
The serialized string of the virtual form in the format of username = % E5 % 95% 8A % E8 % 94% A1 & password = 123456.
The. serialize () method can operate jQuery objects that have selected individual form elements, such,And. However, selectThe serialization of tags is generally easier: $ ('form'). submit (function () {alert ($ (this). serialize (); returnfalse ;});Output standard query string:A = 1 & B; = 2 & c; = 3 & d; = 4 & e; = 5$ POST form submission$. PostJQuery. post (url, [data], [callback], [type]): Use the POST method for asynchronous requests.Parameters:Url (String): the URL of the request.Data (Map): (optional) data to be sent to the server, expressed in Key/value pairs.Callback (Function): (optional) callback Function when the load is successful (this method is called only when the Response returns success ).$. Post ("momsg. php ", {" tel ": $ (" # username "). val ()}, function (data) {if (data = 0) // 0 successful 1 unsuccessful 2 incorrect Mobile Phone Number Format {//}});Use the ajax post request to change the text of the p element:$ ("Input "). keyup (function () {txt = $ ("input "). val (); $. post ("demo_ajax_gethint.asp", {suggest: txt}, function (result) {$ ("span" ).html (result );});});Instance