400错误的请求服务器无法理解请求,原因是格式错误的语法。客户端不应该在没有修改的情况下重复请求。
使用的StatusCode在jQuery的AJAX调用:
<html>
<head>
<title>jquery testing</title>
<script type="text/javascript" src="jquery-1.6.2.min.js"/>"></script>
<script language="javascript">
$(document).ready(
function(){
$('#linkClick').click(
function(){
$.ajax({
url: 'a.html',
data: {},
type: 'get',
dataType: 'json',
statusCode: {
404:function() { alert("404"); },
200:function() { alert("200"); },
201:function() { alert("201"); },
202:function() { alert("202"); }
},
success: function(data) {
alert("Status: " + data);
}
});
});
}
);
</script>
</head>
<body>
<a href="#" id="linkClick">click</a>
</body>
</html>
400是 “正确的”,200是 “礼貌” 的方式。你选。 – 2012-02-19 00:54:30
可能重复[REST HTTP状态码](http://stackoverflow.com/questions/3290182/rest-http-status-codes) – 2012-02-19 00:55:25
非常有趣的问题目前我返回一个空的JSON对象,但那可能不正确,看着最接近的HTTP响应代码将会成为400(不好的请求),有兴趣阅读其他人的观点。 – Dampsquid 2012-02-19 00:56:27