I am highlighting a text and then calling ajax to get get its meaing
but i am not getting data from database neither it shows me any error.. It does show me error alert but not the error
if (!window.Kolich) {
Kolich = {};
}
Kolich.Selector = {};
// getSelected() was borrowed from CodeToad at
// http://www.codetoad.com/javascript_get_selected_text.asp
Kolich.Selector.getSelected = function () {
var t = '';
if (window.getSelection) {
t = window.getSelection();
} else if (document.getSelection) {
t = document.getSelection();
} else if (document.selection) {
t = document.selection.createRange().text;
}
return t;
}
Kolich.Selector.mouseup = function () {
var st = Kolich.Selector.getSelected();
if (st != '') {
$('#noti').css({ 'display': 'block' });
document.getElementById('ajaxtopass').innerHTML = st;
alert(st);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
data: "{ Word: '" + $("#ajaxtopass").text() + "'}",
url: "FetchMeaning",
dataType: "json",
success: function (data) {
var Dictionary = data.d;
$('#noti').append
('<p><strong>' + Dictionary.Word + "</strong><br />" +
Dictionary.Meaning + "<br />" + "</p>");
},
error: function (result) {
alert(result.statusText);
},
});
}
}
$(document).ready(function () {
$(document).bind("mouseup", Kolich.Selector.mouseup);
});
<div class="alert alert-success" id="noti" style="display: none">
</div>
<label id="ajaxtopass"></label>
[WebMethod]
public static Dictionary FetchMeaning(string Word)
{
Dictionary c = new Dictionary();
string connStr = ConfigurationManager.ConnectionStrings["GitaAdmin"].ConnectionString;
string query = "SELECT * FROM TestDelete WHERE Word = @Word";
using (SqlConnection conn = new SqlConnection(connStr))
{
using (SqlCommand cmd = new SqlCommand(query, conn))
{
cmd.Parameters.AddWithValue("@Word", Word);
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.HasRows)
{
while (rdr.Read())
{
c.Word = rdr["Word"].ToString();
c.Meaning = rdr["Meaning"].ToString();
}
}
}
}
return c;
}