我想从我的本地json文件加载数据与jquery文章。但它不适用于我,但当我将$ .post()替换为$ .ajax()时,下面的代码工作正常。但我只想用jQuery Post发布。我在控制台中得到(失败)net :: ERR_FILE_NOT_FOUND。jquery后不工作?
<!DOCTYPE html>
<html>
<head>
<script src="jquery-2.1.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#ajx").click(function(){
$.post({
type:"POST",
dataType:"JSON",
data:{},
url: 'ajax_info.json',
beforeSend:function(){
alert("before ajax");
},
success:function(data){
console.log(data);
},error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
});
});
</script>
</head>
<body>
<input type="button" id="ajx" value="Load File Content">
</body>
</html>
看看的API在http://api.jquery.com/jQuery.post/ –
类型属性不可用在$ .post http://api.jquery.com/jquery.post/ –