JQuery Ajax Application Summary _jquery

Source: Internet
Author: User

An Ajax call in jquery (you need to refer to the jquery code base).

Method 1:

Copy Code code as follows:
$.get (URL, function (data) {
Deal with the data
});

Method 2:

Copy Code code as follows:
Jquery.post (URL, [data], [Success (data, Textstatus, JQXHR)], [DataType])
$.post (Url,postdata, function (data) {
Deal with the data
});

Method 3:

Copy Code code as follows:
$.ajax ({
Type: "POST",//or get
ContentType: "Application/json; Charset=utf-8 ",
Url:url,
Data: "{' Countrymodel ':" + json.stringify (Countrymodel) + "}",
DataType: "JSON",//html,xml,script
Async:true,//true means asynchronous, default is True
Success:function (data) {
Deal with the data
},
Error:function () {
Deal with Error
}
});

Second, Jquery.form plugin Ajax (need to refer to the JQuery code base and Jquery.form plugin)

Ajax calls based on form forms
1.ajaxForm, this method is not submitted immediately when invoked, just stating that the call form is to be submitted in AJAX mode, which is generally in $ (document). Ready method Set.

2.ajaxSubmit, this method will be submitted as soon as it is invoked.

Copy Code code as follows:
var options = {
Target: ' #divToUpdate ',
URL: ' comment.php ',
Success:function () {
Alert (' for your comment! ');
}
};
$ (' #myForm '). Ajaxform (options);
or $ (' #myForm '). Ajaxsubmit (options);

Third, the use of Ajax in MVC
Both of these methods are available,
In addition we can microsoftajax, this must refer to MicrosoftAjax.js, micorsoftmvcajax.js these two files

1.ajax.beginform

Copy Code code as follows:
<%using (Ajax.beginform) ("Action", "Controll", New ajaxoptions
{
Updatetargetid = "Ajaxdiv",
HttpMethod = "POST"
}, new {id = "ajaxform"}))
{%>
<input type= "text" id= "EmployeeId2"/>
<input type= "Submit" value= "Submit"/>
<%}%>
<div id= "Ajaxdiv" >
</div>

2.ajax.actionlink

<%=ajax.actionlink ("Linkname", "Action", "Controll", New ajaxoptions
{
Loadingelementid = "Loadingdiv",
Updatetargetid = "Ajaxdiv",
HttpMethod = "POST"
});%>
<div id= "Ajaxdiv" >
</div>
<div id= "Loadingdiv" >
</div>

Four, Jquery.form and jquery.validate use together

Front-end Code

<script type= "Text/javascript" language= "JavaScript" src= "Http://www.jb51.net/Scripts/jquery-1.4.1.min.js" > </script> <script type= "Text/javascript" language= "JavaScript" src= "http://www.jb51.net/Scripts/" Jquery.validate.min.js "></script> <script type=" Text/javascript "language=" JavaScript "src=" http:// Www.jb51.net/Scripts/jquery.form.js "></script>  

Back-end action

Public Partialviewresult Login (string useremail, String Password)
{

  //Your code return
  Partialview (" Success ");
}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.