【发布时间】:2014-02-15 19:22:20
【问题描述】:
我正在尝试根据用户的兴趣创建一个简单的 Newsfeed 页面。 下面我提供了相同的代码..我只是不明白这里的问题..问题是相同的代码在我的本地主机上运行良好,但在在线服务器上却不一样。但是 $(window) .scroll(function() 工作正常,数据正在正确获取,但 .load() 函数无法获取数据。
我在 javascript Consol.log 中遇到错误
XMLHttpRequest 无法加载 http://redirect.main-hosting.com/error404.php/26?domain=www.nizilla.tk。 请求中不存在“Access-Control-Allow-Origin”标头 资源。因此不允许使用原点“http://www.nizilla.tk” 访问。
我也尝试将 src 路径更改为 src="./profile-newsfeed/jquery-1.9.1.min.js" 但我仍然面临同样的错误。
/*-------------------------------- */
<script src="http://www.nizilla.tk/profile-newsfeed/jquery-1.9.1.min.js"> </script>
<script type="text/javascript">
$(document).ready(function() {
var track_load = 0; //total loaded record group(s)
var loading = false; //to prevents multipal ajax loads
var total_groups = <?php echo $totalpage; ?>; //total record group(s)
//alert(total_groups);
if(total_groups<=0)
{
window.location='http://www.nizilla.tk/profile php/profilefollow.php';//
}
else
{
$('#container').load('http://www.nizilla.tk/profile php/userinterest.php', {'group_no':track_load}, function() {track_load++;}); //load first group
$(window).scroll(function() { //detect page scroll
if($(window).scrollTop() + $(window).height() == $(document).height()) //user scrolled to bottom of the page?
{
if(track_load <= total_groups && loading==false) //there's more data to load
{
loading = true; //prevent further ajax loading
$('.animation_image').show(); //show loading image
//load data from the server using a HTTP POST request
//http://www.nizilla.tk/profile php/userinterest.php
$.post('http://www.nizilla.tk/profile php/userinterest.php',{'group_no': track_load}, function(data){
$("#container").append(data); //append received data into the element
//hide loading image
$('.animation_image').hide(); //hide loading image once data is received
track_load++; //loaded group increment
loading = false;
}).fail(function(xhr, ajaxOptions, thrownError) { //any errors?
alert(thrownError); //alert with HTTP error
$('.animation_image').hide(); //hide loading image
loading = false;
});
}
}
});
}
});
如果您能在这里指出我的错误,那将非常有帮助..非常感谢您的帮助
【问题讨论】:
标签: javascript php jquery ajax