UPDATE:
I am getting the same error. When I click on the x, it should be returning {id: 23}, but it is returning {id: NaN} instead. This problem corrects itself if I remove the ternary operator.
I have made a change to my webpage:
It was this:
$( "#notifications" ).prepend( "<div class='notification' id='n" + notifications.d[i].id + "'><span class='notification_text'>" + notifications.d[i].text + "</span><a href='#' class='notification_button' id='b" + notifications.d[i].id + "' value='x'>x</a></div>" ).show();
and I changed it to this, added a ternary condition depending on the value of notifications.d[i].sticky:
$( "#notifications" ).prepend( "<div class='notification' id='n" + notifications.d[i].id + "'><span class='notification_text'>" + notifications.d[i].text + "</span>" + ( notifications.d[i].sticky ? "" : "<a href='#' class='notification_button' id='b'" + notifications.d[i].id + "' value='x'>x</a>'" ) + "</div>" ).show();
That part works fine, it not creating the x link if sticky is true.
However, when I click on any other x, I get a serverside error message:
NaN is not a valid value of Int32
The serverside code looks like this:
[WebMethod()]
public int CloseNotification(int id) {
using (connection = new SqlConnection(ConfigurationManager.AppSettings["connString"])) {
using (command = new SqlCommand("update notifications set closed_by = @user where id = @id", connection)) {
command.Parameters.Add("@id", SqlDbType.Int, 4).Value = id;
command.Parameters.Add("@user", SqlDbType.VarChar, 4).Value = "abc";
connection.Open();
intAffectedRows = command.ExecuteNonQuery();
connection.Close();
}
}
return intAffectedRows;
}
Anyone know why I am getting that error?
I’m thinking I’ve made a mistake with the ternary section, probably a double or single quote mistake, but I can’t see it.
You have a Syntax error in your code on the line that reads
There is an extra
'after theb. It should read:Edit:
You also have an extra
'at the end of your ternary operation.should be: