当前位置: 编程技术>jquery
jquery异步请求并改变页面内容的实例分析
来源: 互联网 发布时间:2014-09-03
本文导语: 1,jquery代码 /** * jquery异步请求 * edit www. */ var path = 'index.php?d='+Math.random()+'&act=favorite'; $(document).ready(function(){ $("#selectFavOrSha").change(function(){ //var data = {type:'ajaxFS',index:this.value}; //ajaxSend(path,data,'json',...
1,jquery代码
/**
* jquery异步请求
* edit www.
*/
var path = 'index.php?d='+Math.random()+'&act=favorite';
$(document).ready(function(){
$("#selectFavOrSha").change(function(){
//var data = {type:'ajaxFS',index:this.value};
//ajaxSend(path,data,'json',true);
document.getElementById("answerContent").innerHTML = "
";
$.ajax({
url:path,
data:{type:'ajaxF',index:this.value},
type:'post',
dataType:'json',
success:function(data){
if(data.success){
document.getElementById("answerContent").innerHTML = data.msg;
}else{
alert('系统错误!请联系客服!');
}
}
});
});
});
php测试代码:
记住,这里用json_encode方法是很有必要的,可以避免意外情况的出现,比如html代码的解析以及特殊字符的处理等。
data.msg返回的内容就是good。
简单吧,就是这些了,希望对大家有所帮助。