I need to get the value of textbox as I type, and perform a function of JSON, I tried doing this:
$(document).ready(function () {
$("#<%= txtBusca.ClientID %>").keypress(function () {
$.ajax({
type: "POST",
data: "{ 'valor' : '" + $(this).val() + "'}",
url: "Especialidades.aspx/Buscar",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert('OK');
}
})
});
});
But it doesn’t work.
I think the line below is causing the problem
The reason is this keyword. In your code it is referring ajax context.
I recommend you to assign this into variable before Ajax call blocks and refer it inside like the following :