$.ajax和$.get写法注意

function zan(){
	 var $resId =  $("#zan").attr("class");
	 var $url = '{:U("Search/zan")}';
	 $.get($url,{'resId':$resId},function(json){
			var backstatus = json.info;
			if(backstatus == "赞成功"){
				$("#zan").load(location.href+" .zan");//局部刷新
		  	}else{
		  		alert('*未知错误*');	
		  	}
	    }); 
}
/*下面一样的*/
 function zan(){
	 var $resId =  $("#zan").attr("class"); 
	 var $url = '{:U("Search/zan")}'; 
	 $.ajax({
		 type:"GET",
		 url:$url,
		 data:{'resId':$resId},
		 dataType: "json",
		 success:function(json){
			var backstatus = json.info;
			if(backstatus == "赞成功"){
				$("#zan").load(location.href+" .zan");//局部刷新
		  	}else{
		  		alert('*未知错误*');	
		  	}
		 }
	    }); 
}
<a id="zan" class="{$vo['resId']}" onclick="zan()" href="javascript:void(0)"><span class="zan">赞{$vo['topCount']}</span></a>
 
 

转载请注明:PHP博客 » $.ajax和$.get写法注意

你可能感兴趣的:($.ajax和$.get写法注意)