here is the getter method in c# it gets the meanings of a word input by a user by a query and fills them in a data table afterwards a list of strings will be filled by a loop which will contain those meanings which is at last converted and return as json string :
public static string getmeanings(string word)
{
string cs =
ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
List<string> stringArr = new List<string>();
using (SqlConnection con = new SqlConnection(cs))
{
con.Open();
using (SqlDataAdapter rdr = new SqlDataAdapter("SELECT MEANING FROM WORDS T1 , MEANINGS T2 WHERE WORD LIKE N'" + word + "'AND T1.WORD_ID = T2.WORD_ID", con))
{
using (DataTable dt = new DataTable())
{
rdr.Fill(dt);
for(int i =1;i< dt.Rows.Count; i++)
{
stringArr.Add(dt.Rows[0][i].ToString());
}
}
string json1 = JsonConvert.SerializeObject( stringArr);
return json1;
}
}
}
here is the ajax/jquery code : on keyup the ajax will call the getter method and at success it will alter a table that contains the result of the return json object
$(function () {
$("#text1").keyup( function () {
var word = $("#text1").val();
$.ajax({
type: "GET",
url: "toshow.aspx/getmeanings",
data: { word: word },
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (result) {
$(".tablefill").append("<table><tr><td>meaning id</td><td>meaning</td></tr><tr><td>"+result[0]+"</td></tr></table>");
console.log(result);
}, error: function (err) {
alert('ERROR');
}
});
});
});
after i test the code ajax is succeeding , no error or failure but the result is always an undefined object in console log