$.ajax(options)
常用设置项
url - 发送请求地址
type - 请求类型 get|post
data - 向服务传递的参数
dataType - 服务器响应的数据类型 text|json|xml|html|jsonp|script
success - 接收响应时的处理函数
error - 请求失败时的处理函数
java
<script type="text/javascript">
$(function() {
$.ajax({
"url" : "/ajax/news_list",
"type" : "get",
"data":{"t":"pypl","abc":"123","uu":"777"},
//"data" : "t=pypl&abc=123&uu=777",
"dataType" : "json",
"success" : function(json) {
console.log(json);
for(var i=0;i<json.length;i++){
$("#container").append("<h1>"+json[i].title+"</h1>");
}
},
"error":function(xmlhttp,errorText){
console.log(xmlhttp);
console.log(errorText);
if(xmlhttp.status=="405"){
alert("无效的请求方式");
}else if(xmlhttp.status=="405"){
alert("未找到URL资源");
}else if(xmlhttp.status=="500"){
alert("服务器内部错误,请联系管理员");
}else{
alert("产生异常,请联系管理员");
}
}
})
})
</script>