jQuery ajax應(yīng)用總結(jié)
一、jQuery中Ajax的調(diào)用(需要引用jQuery代碼庫(kù))。
方法1:
//deal with the data
});
方法2:
$.post(url,postdata, function(data) {
//deal with the data
});
方法3:
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 表示異步,默認(rèn)就是true
success: function(data) {
//deal with the data
},
error: function() {
// deal with error
}
});
二、jQuery.Form plugin Ajax(需要引用jQuery代碼庫(kù)和jQuery.Form插件)
基于Form表單的Ajax調(diào)用
1.ajaxForm, 這個(gè)方法在調(diào)用時(shí)不是馬上提交,只是說(shuō)明調(diào)用的Form要以ajax方式提交,該方法一般在$(document).ready方法里設(shè)置。
2.ajaxSubmit,這個(gè)方法在調(diào)用時(shí)就會(huì)馬上提交。
target: '#divToUpdate',
url: 'comment.php',
success: function() {
alert('Thanks for your comment!');
}
};
$('#myForm').ajaxForm(options);
或$('#myForm').ajaxSubmit(options);
三、Ajax在MVC中的使用
以上兩種方法都可以用,
另外我們可以MicrosoftAjax,這就必須引用MicrosoftAjax.js, MicorsoftMvcAjax.js這兩個(gè)文件
1.Ajax.BeginForm
{
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>
四、jquery.form與jquery.validate結(jié)合使用
前端代碼
<script type="text/javascript" language="javascript" src="http://www.dbjr.com.cn/Scripts/jquery-1.4.1.min.js"></script> <script type="text/javascript" language="javascript" src="http://www.dbjr.com.cn/Scripts/jquery.validate.min.js"></script> <script type="text/javascript" language="javascript" src="http://www.dbjr.com.cn/Scripts/jquery.form.js"></script> <h2> AjaxFrom</h2> <div id="output1" style="color: Red;"> </div> <%using (Html.BeginForm("Login", "Home", FormMethod.Post, new { id = "loginForm" })) { %> <table border="0" cellpadding="0" cellspacing="0"> <tr> <td> <%=Html.TextBox("UserEmail", "", new { @class="name required"})%> </td> </tr> <tr> <td> <%=Html.Password("Password", "", new { @class = "required" })%> </td> </tr> <tr> <td> <input type="submit" value="submit" /> </td> </tr> </table> <%} %> <script language="javascript" type="text/javascript"> $(document).ready(function () { var opts = { submitHandler: function (form) { var submitOpts = { target: '#output1', success: function () { alert('Thanks for your comment!'); } }; $(form).ajaxSubmit(submitOpts); } }; jQuery("#loginForm").validate(opts); }); </script>
后端Action
public PartialViewResult Login(string UserEmail, string Password) { // you code return PartialView("Success"); }
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- javascript jQuery $.post $.ajax用法
- 基于JQuery框架的AJAX實(shí)例代碼
- jquery ajax提交表單數(shù)據(jù)的兩種方式
- JQuery AJAX提交中文亂碼的解決方案
- Jquery ajaxsubmit上傳圖片實(shí)現(xiàn)代碼
- 用jQuery中的ajax分頁(yè)實(shí)現(xiàn)代碼
- 基于jquery的$.ajax async使用
- jquery的ajax()函數(shù)傳值中文亂碼解決方法介紹
- Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法總結(jié)
- jquery實(shí)現(xiàn)ajax提交form表單的方法總結(jié)
- MVC+jQuery.Ajax異步實(shí)現(xiàn)增刪改查和分頁(yè)
- jquery的ajax提交form表單的兩種方法小結(jié)(推薦)
相關(guān)文章
jquery實(shí)現(xiàn)標(biāo)簽上移、下移、置頂
這篇文章主要介紹了jquery實(shí)現(xiàn)標(biāo)簽上移、下移、置頂?shù)南嚓P(guān)資料,并附上示例,非常實(shí)用,需要的朋友可以參考下2015-04-04解析頁(yè)面加載與js函數(shù)的執(zhí)行 onload or ready
這篇文章主要介紹了頁(yè)面加載與js函數(shù)的執(zhí)行 onload or ready 需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12關(guān)于Jquery中的bind(),on()綁定事件方式總結(jié)
下面小編就為大家?guī)?lái)一篇關(guān)于Jquery中的bind(),on()綁定事件方式總結(jié)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10jQuery過(guò)濾特殊字符及JS字符串轉(zhuǎn)為數(shù)字
這篇文章主要介紹了jQuery過(guò)濾特殊字符及JS字符串轉(zhuǎn)為數(shù)字 的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下2016-05-05jQuery常用數(shù)據(jù)處理方法小結(jié)
這篇文章主要介紹了jQuery常用數(shù)據(jù)處理方法,實(shí)例總結(jié)了trim、param、isArray、isFunction、each等jQuery常用的數(shù)據(jù)處理方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02基于jQuery實(shí)現(xiàn)的向下滑動(dòng)二級(jí)菜單效果代碼
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)的向下滑動(dòng)二級(jí)菜單效果代碼,通過(guò)jquery鼠標(biāo)事件控制針對(duì)頁(yè)面元素的鏈?zhǔn)讲僮鲗?shí)現(xiàn)菜單切換的功能,非常簡(jiǎn)單實(shí)用,需要的朋友可以參考下2015-08-08