I am currently facing an issue while working on a project. I cannot seem to figure out what is wrong with my code. Below is the snippet of my code where I am having trouble with the Ajax url not being able to access the function ReceivedMessageByIndexNumber in default.aspx. Any help would be greatly appreciated.
JavaScript:
ReceivedMessage(1);
function ReceivedMessage(indexNumber)
{
$.ajax({
type: "Post",
url: "Default.aspx/ReceivedMessageByIndexNumber?indexNumber="+indexNumber,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var data = response.d;
for (var i = 0; i < data.length; i++) {
alert(data[i]);
}
},
failure: function (msg) {
$('#output').text(msg);
}
});
}
Default.aspx :
[WebMethod]
public static bool ReceivedMessageByIndexNumber(int textIndex)
{
string connectionString = @"Data Source=localhost;Initial Catalog=NotificationSystem;Integrated Security=True";
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = connection.CreateCommand())
{
connection.Open();
command.CommandText = @"SELECT TextWord FROM TextProperty WHERE TextIndex = '" + textIndex + "'";
command.ExecuteNonQuery();
return true;
}
}