我对asp.net毫无新意,我想用jQuery Ajax和ASP.NET MVC创建无限滚动。所以在这里,是我走到这一步,ASP.NET Ajax代码为0的代码错误
<div id="container"></div>
<div id="progress" style="display:none">
<h4>Loading...</h4>
<div class="col-md-12 panel panel-default"></div>
</div>
<script type="text/javascript">
var pageSize = 10;
var pageIndex = 0;
$(document).ready(function() {
GetData();
$(window).scroll(function() {
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
GetData();
}
});
});
function GetData() {
$.ajax({
type: 'GET',
url: 'http://localhost:64949/api/values/delfi',
dataType: 'json',
success: function(data) {
alert("yra");
//if (data != null) {
// for (var i = 0; i < data.length; i++) {
// $("#container").append("<h2>" +
// data[i].CompanyName + "</h2>");
// }
// pageIndex++;
//}
},
beforeSend: function() {
$("#progress").show();
},
complete: function() {
$("#progress").hide();
},
error: function(jqXHR, exception) {
var msg = '';
if (jqXHR.status === 0) {
msg = 'Not connect.\n Verify Network.' + jqXHR.responseText;
} else if (jqXHR.status == 404) {
msg = 'Requested page not found. [404]' + jqXHR.responseText;
} else if (jqXHR.status == 500) {
msg = 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg = 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg = 'Time out error.';
} else if (exception === 'abort') {
msg = 'Ajax request aborted.';
} else {
msg = 'Uncaught Error.\n' + jqXHR.responseText;
}
alert(msg);
}
});
}
</script>
我impemented滚动收听我每次到达页面的结束时间,我让我的API,它只是返回json
数据的新要求。下面是它返回
[{"Index":1,"List":{"Img":"http://g1.dcdn.lt/images/pix/jonas-udris-72559208.jpg","Title":"J. Udris. Scenarijai dėl Šilutės balsavimo reikalų","Description":"Policijai pradėjo ikiteisminį tyrimą dėl galimo rinkėjų papirkimo Šilutės rajone partijos „Tvarka ir teisingumas naudai. Ketvirtadienį policija pranešė sulaikiusi septynis asmenis, antradienį jų namuose atliktos kratos. Vienas asmuo suimtas 10 parų."}}]
但是每一个我的ajax跳转到误差函数和jqXHR.status始终是0。我也试图通过URL这样的URL时间:localhost:64949/api/values/delfi
,仍然得到同样的反应。我的代码有什么问题?
你可以通过浏览器打开http:// localhost:64949/api/values/delfi吗? – Imad
@ImadYes,我实际上'json'数据是我的问题是从浏览器窗口复制 – David