jQuery ajax应用总结

jQuery ajax应用总结

一、jQuery中Ajax的调用(需要引用jQuery代码库)。

方法1:

$.get(url, function(data) {

//deal with the data

});

方法2:

jQuery.post( url, [ data ], [ success(data, textStatus, jqXHR) ], [ dataType ] )

$.post(url,postdata, function(data) {

 //deal with the data

});

方法3:

$.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 表示异步,默认就是true

success: function(data) {

  //deal with the data

},

error: function() {

// deal with error

}

});

二、jQuery.Form plugin Ajax(需要引用jQuery代码库和jQuery.Form插件)

基于Form表单的Ajax调用

1.ajaxForm, 这个方法在调用时不是马上提交,只是说明调用的Form要以ajax方式提交,该方法一般在$(document).ready方法里设置。

2.ajaxSubmit,这个方法在调用时就会马上提交。

var options = {

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这两个文件

1.Ajax.BeginForm

© 版权声明

相关文章

暂无评论

none
暂无评论...