【发布时间】:2012-06-16 14:19:41
【问题描述】:
这是我在一个网站上找到的非常简单的 jQuery 代码:
//It simply loads more news
function ReadMore(page){
$("#news-list").html('Loading More News...');
$("#news-list").append('<img src="/images/loading.gif">');
next=parseInt(page)+1;
html=$.get('/morenews.php','page='+page,function (data){
$("#News").append(data);
$("#news-list").html("<a href='javascript:void(0);' onclick='ReadMore("+next+");'>More News</a>");
});
}
我的问题是:
它使用什么样的数据类型? "响应的预期数据类型。以下之一:null、'xml'、'script' 或 'json'。"
jQuery 中的
html=$.get('/newread.php','page='+page,function (data){}是什么?我从未见过$.get,似乎只有一个参数page。服务器是否收到类似这样的信息:/morenews.php?page=3
此代码无法处理错误。如果服务器太忙,比如说20秒什么都不做,怎么加一些错误信息?
顺便说一句,jQuery 似乎是一种奇怪的语言,因为它不断创建匿名函数。
【问题讨论】:
-
jQuery 不是一种语言,而是一个 JavaScript 库。 Reading through the documentation 可能是一个好的开始,特别是
$.get() -
如果您对某个问题投了反对票,您应该说出原因!
标签: javascript jquery html