function updateMsg(num) {
var nowpage = parseInt($("#vypis dl").attr("page")) + num;
alert("1");
$.ajax({
type: "GET",
url: "json.aspx",
dataType: "json",
beforeSend: function() { addmask(); alert("2"); },
error: function(textStatus,errorThrown) { alert(textStatus.toString()+errorThrown.toString());alert("4"); removemask(); },
success: function(data) {
alert("3");
var ms = "";
$("#vypis dl").attr("page", nowpage);
var pagecount = parseInt((data.Guest.length + 2) / 3);
try {
for (var i = 0; i < 3; i++) {
ms = ms + "<dt><strong>" + data.Guest[(nowpage - 1) * 3 + i].Title + "</strong></dt><dd><em title=" + data.Guest[(nowpage - 1) * 3 + i].Content + ">" + data.Guest[(nowpage - 1) * 3 + i].Content + "</em><br><span>" + data.Guest[(nowpage - 1) * 3 + i].Name + ": <strong>" + data.Guest[(nowpage - 1) * 3 + i].DateTime + "</strong></span></dd>";
}
}
catch (e) { }
if ((data.Guest.length + 2) / 3 == nowpage) { $("#next").css("display", "none"); } else { $("#next").removeAttr("style"); }
if (nowpage == 1 || pagecount == 1) { $("#prev").css("display", "none"); } else { $("#prev").removeAttr("style"); }
$("#PageIndex").text(nowpage + "/" + pagecount);
$("#vypis dl").html(ms);
},
complete: function() { removemask(); alert("5"); }
});
alert("6");
}
火狐下没问题,ie8下也没问题。
为什么每次都要两个分号(;)?
json.aspx 中设置Response.ContentType为json格式。
如果上面的代码没有问题,你每个换行都多一个分号。你可以看看这篇文章:http://www.cnblogs.com/sky-earth/archive/2009/12/22/1630053.html
以前写过:
function PageAjaxServiceTest() {
$.ajax({
type: "POST",
contentType: "application/json;utf-8",
url: "PageService.aspx/AjaxServiceTest",
data: "{str:\"" + $("#inputName").val() + "\"}", //传到.cs静态方法的参数,str是方法的参数,必须一致
success: function(data) {
//将返回字符串转换为json对象
var json = null;
try {
json = eval('(' + data + ')');
} catch (e) {
alert("返回字符串不是json格式!");
return;
}
alert(json.d);
}
});
}