Here is my situation: I have an object UserBadgein ASP.NET, it contains 3 fields, which is the object User, Badgeand boolean(isNotified) to check if the user has been notified of the receipt of the icon. I am having trouble sending certain UserBadgeof this WebMethod():
[WebMethod()]
public static UserBadge Notify()
{
var db = new achievDb();
foreach (var uB in db.UserBadges)
{
if (System.Web.HttpContext.Current.User.Identity.Name == uB.User.UserName)
{
if (!uB.isNotified)
{
return uB;
}
}
}
return null;
}
on mine $.ajax:
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "POST",
url: "../NotifCodeBehind.aspx/Notify",
data: "{}",
complete: function (result) {
if (result) {
$("#notify").jGrowl("You've unlocked a badge!", { header: 'Yay', close: function () {
$.ajax({
type: "POST",
url: "../NotifCodeBehind.aspx/Notified",
data: "{}",
success: function (ub) { DoCallback(JSON.stringify(ub)); },
error: function () { DoCallback("NOPE!") }
});
}
})
};
function DoCallback(msg) {
alert(msg);
}
}
})
})
</script>
and then back to another WebMethod(), which sets the value isNotified booleanto true after the notification is closed:
[WebMethod()]
public static void Notified(UserBadge ub)
{
var db = new achievDb();
foreach (var userbadge in db.UserBadges)
{
if (userbadge.UserId == ub.UserId && userbadge.BadgeId == ub.UserId)
{
userbadge.isNotified = true;
db.SaveChanges();
}
}
}
:
, ajax, ... 1,5 , . , , jQuery/Ajax/JSON.
, , !
EDIT:
JavaScript , , , .
EDIT2:
, WebMethods.