0
我碰到這種奇怪的JSON行爲..我只是無法弄清楚到底是怎麼回事..ASP.net 3.5的WebMethod奇怪的行爲,jQuery的AJAX收到奇怪的數據
我有一個WebMethod在我的asp.net頁面..它重複調用通過jQuery AJAX頁面加載..一切都很順利,但奇怪的事情發生的是,我感覺到我的jQuery Ajax數據不是我剛發送的同一個。:S
這裏就不頁方法的代碼
[WebMethod()]
public static List<Unister.UnisterCore.Core.Domain.Comment> LoadComments(long objID, int sysID)
{
if (objID == 0)
return null;
UnisterWeb.UserControls.Presenter.CommentsPresenter _presneter;
_presneter = new UnisterWeb.UserControls.Presenter.CommentsPresenter();
List<Unister.UnisterCore.Core.Domain.Comment> comments = new List<Unister.UnisterCore.Core.Domain.Comment>();
comments = _presneter.LoadComments(sysID, objID);
if (comments.Count == 0)
return null;
return comments;
}
這裏返回列表我從演示者層獲得了什麼,但是當我在我的js方法中收到它時,它的空值或以前的值。
這裏是我的jQuery的方法..
function LoadComments(SysID, ObjID) {
if (parseInt(SysID) == 0 || parseInt(ObjID) == 0)
return;
var args = 'objID:' + ObjID + ',sysID:' + SysID;
$.ajax({
type: "POST",
url: "/dashboard/default.aspx/LoadComments",
cache: false,
data: '{' + args + '}',
contentType: "application/json",
dataType: "json",
success: function(result) {
if (result.d != null) {
comments = new Array();
$.each(result.d, function(key, val) {
data = new Object();
data.CommentID = val.CommentID;
data.Body = val.Body;
codate = new Date(parseInt(val.CreateDate.replace("/Date(", "").replace(")/", ""), 10));
var fdate = dateFormat(codate, "isoUtcDateTime");
ldate = $.timeago(fdate);
data.CreateDate = ldate;
data.CommentByAccountID = val.CommentByAccountID;
comments.push(data);
});
var boxid = "#commentBox_" + ObjID;
$(boxid).setTemplateURL("../Templates/comments.htm");
$(boxid).processTemplate(comments);
}
}
});
}
請幫助我..
你在一個用戶控件使用它調用Web方法在一個循環 – Rafay
林其通過中繼器加載..簡而言之是即時通訊在循環中使用 – casper123
嘗試在ajax請求中設置'async:false'看看是否可以解決問題,但不建議 – Rafay