$.ajax({
type:"POST",
url:"some.php",
data:"name=John&location=Boston",
success:function(msg){
alert("DataSaved:"+msg);});//网址为some.php?name=John&location=Boston
jquery中使用ajax的几种常用写法
第一种:
$.ajax({
type:"POST",
url:"",
data:'{CategoryId:"'+CategoryId+'"}',
contentType:"application/json;charset=utf-8",
dataType:"json",
success:function(data){
varitem=eval(data.d);
varStrHtml="";
for(variinitem){}
},async:false第二种:
$(document).ready(function(){
$("#").click(function(){
htmlobj=$.ajax({url:"/jquery/test1.txt",async:false});
$("#myDiv").html(htmlobj.responseText);});
第三种:
$.ajax({url:"test.html",context:document.body,success:function(){
$(this).addClass("done");
}});
ajax两种写法的区别???
两者是一样的效果。
这两种,只是内部封装不一样。第一种是把请求地址放到了外面,而把你要发送的数据,都放到了一个JSON中。内部会构造成一个AJAX请求的。
而第二种,把你所有能用到的都放到了一个JSON数据中去了。
这两种,相对来说,我更喜欢第二种方法。
第二种方法,把所有的数据写在一个JSON数据中。它没有顺序限制,你哪个在前,哪个在后,都不影响的。相对来说更灵活一点。
jquery里面的$ajax怎么写异步请求求帮助
datatype类型看需求。
$.ajax({
url:"../xx/xx",
type:"GET",
data:{
id:iddatatype:"text",
success:function(data){
alert(data);})