I am trying implement a search box functionality and whenever user presses enter I am calling $.getJSON
to query my web service. The problem is I can see that my keypress is handler is called but it never executes $.getJSON()
.
EDIT: I debugged further using Fiddler. I can see that request is going out and I get a HTTP 200 response. Now I am surprised why the remaining part of code is not executed.
What could be the problem?
$(document).ready(function() {
$("#searchUser").keypress(function (event) {
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
var queryString = this.value;
$.getJSON("/api/users", function(result) {
if (result != null) {
result = sortJSON(result, 'name');
var html = '<tbody>';
var i = 0;
for ( i = 0; i < result.length; i++) {
var j = 0;
var groups = '';
html += '<tr>';
html += '<td>' + result[i].id + '</td>';
html += '<td>' + result[i].emailAddress + '</td>';
html += '<td>' + result[i].name + '</td>';
result[i].groups = sortJSON(result[i].groups, 'name');
for ( j = 0; j < result[i].groups.length; j++) {
groups += result[i].groups[j].name + ", ";
}
html += '<td>' + groups + '</td>';
html += '<td>' + result[i].department.name + '</td>';
html += '<td>SK</td>';
html += '</tr>';
}
html += '</tbody>';
$('#dataTable').append(html);
}
});
}
event.stopPropagation();
});
});