Why is my jQuery button handler not being fired?
I have this jQuery to respond to a button being clicked and call an AJAX method:
-
$(document).ready(function() {
$("#btnGetData").click(function() {
alert("The button was clicked.");
var unitval = _unit;
var begdateval = _beginDate;
var enddateval = _endDate;
var model = JSON.stringify({ unit: unitval, begdate: begdateval, enddate: enddateval });
$.ajax({
type: 'GET',
url: '@Url.Action("GetQuadrantData", "LandingPage")',
data: { unit: unitval, begdate: begdateval, enddate: enddateval},
contentType: 'application/json',
cache: false,
success: function (returneddata) {
},
error: function () {
alert('hey, boo-boo!');
}
});
}); // button click
}); // ready
It is not just that the REST method is not getting called - this handler is apparently not firing at all, as I see no alerts (neither "The button was clicked." nor "hey, boo-boo!").
The script *is* being added - I can step through it, and the vars (such as "unitval") *are* being assigned the appropriate values.
So why does clicking the button, which is declared like so:
- <button class="btn green smallbutton" id="btnGetData" name="btnGetData">SUBMIT</button>
...do nothing?