Why is my jQuery button handler not being fired?

前端 未结 5 1298
独厮守ぢ
独厮守ぢ 2020-12-22 13:32

I have this jQuery to respond to a button being clicked and call a REST method:

$(document).ready(function() {
    $(\"#btnGetData\").click(function() {
             


        
5条回答
  •  佛祖请我去吃肉
    2020-12-22 14:06

    Try this out, it simply uses vanilla JS to setup your listener then handles the rest with jQuery.

    On the test page I made, I was getting my alert just fine.

    window.onload = function() {
        var btnGetData = document.getElementById('btnGetData')
        btnGetData.addEventListener("click", function() {
            alert("Twerking...");
            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
    }
    

提交回复
热议问题