我试图使用$.ajax获得一个变量值,如下所示:
function ConfirmFriend(friendID, addOrDecline) {
//Ajax Call Get All Employee Records
$.ajax({
type: "GET",
cache: false,
url: "Home/GetLiveFriends",
data: {},
success: function (data) {
var testnum = data;
if (testnum == 0 && addOrDecline == "add") {
OpenBadges.issue(["https://company.blob.core.windows.net/badges/1.json"]);
}
var userID = '@ViewBag.UserID';
var postData = {
'userID': userID,
'userFriendID': friendID,
'addOrDelete': addOrDecline
};
$.post('/User/Show/', postData, function (data) {
});
document.getElementById("HiddenPendingFriends" + friendID).style.display = 'none';
if (addOrDecline == 'add') {
document.getElementById("HiddenAcceptedFriends" + friendID).style.display = 'block';
}
else {
document.getElementById("HiddenDeclinedFriends" + friendID).style.display = 'block';
}
},
error: function (xhr, textStatus, error, exception) {
alert(error.status + "<--and--> " + error.statusText);
alert(exception);
alert(xhr.statusText);
alert(textStatus.data);
alert(error);
}
});
};
我的主控制器方法如下所示,并调用HomeViewModel:
public int GetLiveFriends()
{
return hvm.GetLiveFriends();
}
我的HomeViewModel代码如下:
public int GetLiveFriends()
{
return friendRepository.Get(f => f.FriendUserID == User.UserID && f.Accepted == 1).Count();
}
如果我从/Admin、/Home、/Profile等调用它,那么它将按预期工作并返回计数,但是如果我从/Admin/page或/Home/page或/Profile/page调用它,那么会产生什么未定义的错误?
发布于 2014-03-13 09:53:57
我通过将URL更改为url:"/Home/GetLiveFriends“来解决这个问题,在我的评论中已经提到了这一点。
发布于 2014-03-07 12:42:41
试试这个网址:"/Home/GetLiveFriends“。
"Home/GetLiveFriends“是相对的url。目标页取决于当前url地址。"/Home/GetLiveFriends“-绝对在你的领地上。目标地址从域名/*您的绝对网址*开始。
https://stackoverflow.com/questions/22249591
复制相似问题